The two main Python libraries for HDF5 interaction are h5py and pytables. They don't play nicely together, particularly on windows
>>> import tables
>>> import h5py
ImportError: DLL load failed
>>> import h5py
>>> import tables # works fine
I need to use both in the same application but I'm unable to get full functionality from both libraries when each is imported. Is there a solution to this?
According to this thread on github no, I don't think you can. It seems that h5py cannot do anything about it, so I would start an issue with the pytables github.
Also, could you possibly use two different scripts? That way the import wouldn't bork.
Are you using conda to install packages? If yes, it looks like an issue reported on GitHub. That issue to me seems like an issue with build 0 of version 2.4.0 of h5py. Try downgrading to version 2.3.x. That works just fine for me.
Related
When I tried to read a pickle file that saved by a former version of pandas, it yielded an ImportError.
ImportError: No module named 'pandas.core.internals.managers';
'pandas.core.internals' is not a package
There was no hit on stackoverflow so i would like to share my solution for this particular problem.
This error comes off due to encoding of formerly saved pickle file. If you updated pandas to newly amended version, it produces this import error.
I was facing the same error when I was using pandas version 0.23.4.
I have installed pandas 0.24.1 version explicitly by:
pip3 install pandas==0.24.1
This solved my problem(Python version I was using was 3.5)
I had the same problem, but for me, it seemed to come from the pickle package / interaction with the pandas package.
I had Pandas version 0.23.4.
I saved some pickle files with pandas.Dataframe.to_pickle, with python 3.6.6 & Pandas version 0.23.4.
Then I upgraded to python 3.7.2 (Pandas version 0.23.4), and was enabled to read thoses pickle files with pandas.Dataframe.read_pickle.
Next, I upgraded pandas to pandas 0.24.1, and it worked for me. I can read those files again.
Updating pandas would be the best solution for most cases. However if you have limitations updating your pandas version, and you need to consume pandas objects produced and pickled in a higher version, you can add class location map as below.
from pandas.compat.pickle_compat import _class_locations_map
_class_locations_map.update({
('pandas.core.internals.managers', 'BlockManager'): ('pandas.core.internals', 'BlockManager')
})
conda update pandas
If you use conda package manager.
So, just to be clear, I'm very new to python coding... so I'm not exactly sure what's going wrong.
Yesterday, whilst following a tutorial on calling python from R, I successfully installed and used several python packages (e.g., NumPy, pandas, matplotlib etc).
But today, when trying to run the exact same code, I'm getting an error when trying to import pandas (NumPy is importing without any errors). The error states:
ModuleNotFoundError: No module named 'pandas'
I'm not sure what's going on!?
I'm using R-Studio (running on a Mac)... here's a code snippet of how I'm doing it:
library(reticulate)
os <- import("os") # Setting directory
os$getcwd()
repl_python() #used to make it interactive
import numpy as np. # Load numpy package
import pandas as pd # Load pandas package
At this point, it's throwing me an error. I've tried googling the answer and searching here, but to no avail.
Any suggestions as to how I'd fix this problem, or what is going on?
Thanks
Possibly your python path for reticulate changed upon reloading Rstudio. Here is how to set the path manually (filepath for Linux or Mac):
library(reticulate)
path_to_python <- "~/anaconda3/bin/python"
use_python(path_to_python)
https://stackoverflow.com/a/45891929/4549682
You can check your Python path with py_config(): https://rstudio.github.io/reticulate/articles/versions.html#configuration-info
I recommend using Anaconda for your Python distribution (you might have to use Anaconda anyway for reticulate, not sure). Download it from here: https://www.anaconda.com/distribution/#download-section
Then you can create the environment for reticulate to use:
conda_create('r-reticulate', packages = "python=3.5")
I use Python 3.5 for some specific packages, but you can change that version or leave it as just 'python' for the latest version.
https://www.rdocumentation.org/packages/reticulate/versions/1.10/topics/conda-tools
Then you want to install the packages you need (if they aren't already) with
conda_install('re-reticulate', packages = 'numpy')
The way I use something like numpy is
np <- import('numpy')
np$arange(10)
You need to set the second argument of the function use_python, so it should be:
For example, use_python("/users/my_user/Anaconda3/python.exe",required = TRUE)
DON'T forget required = TRUE
I have ARCGIS 10.2 . When we install this software, python 2.7.3 (on win32) is also installed which we can develop the software by python and by arcpy module. I want to add h5py to it's library. My windows is 64 bit and I downloaded both hy5py 32 and 64 bit and copied them to the Lib folder. When I open IDLE an try to import it, I encounter with the following error:
"ValueError: numpy.dtype has the wrong size, try recompiling".
I also copied six. and I think the problem is with numpy. I replaced the numpy from anaconda(numpy 1.9) with numpy in ARCGIS python Library. Then I could import h5py but I could not open arcpy.
I really appreciate for your help
It sounds like the NumPy that came with your system was built one way, with one version, then you "installed" (by copying) h5py which was built another way, either with a different version or different options for NumPy.
To fix this, you should try building h5py yourself, which you can do by downloading the Source from here: https://pypi.python.org/pypi/h5py/2.5.0
Or perhaps easier, consider using Pandas. It can also read and write hdf5 files (though perhaps with fewer arcane features), and it's quite likely that someone has already provided a package for Pandas which is compatible with your existing installation.
My installed version of the python(2.7) module pandas (0.14.0) will not import. The message I receive is this:
UserWarning: Installed openpyxl is not supported at this time. Use >=1.6.1 and <2.0.0.
Here's the problem - I already have openpyxl version 1.8.6 installed so I can't figure out what the problem might be! Does anybody know where the issue may lie? Do I need a different combination of versions?
The best thing would be to remove the version of openpyxl you installed and let Pandas take care.
I got this simple problem and I can't find the answer anywhere, I'm wasting a lot of time!
I did a Python programm on Linux (which works OK), but when I try to run it on Windows, there are too problems with libs...
I have installed the libs I need (dateutil, lxml, xmlrpclib...) in C:\Python34\Lib\site-packages. But then, they don't work as they do on Linux. For example:
from dateutil.tz import tzlocal
Gives me next error:
File "C:\Python34\lib\site-packages\dateutil\tz.py", line 9, in module
from six import string_types, PY3 ImportError: No module named 'six'
That is, they are not finding the other modules... why???
Have you try this ?
http://www.instructables.com/id/How-to-install-Python-packages-on-Windows-7/
Maybe it can help
It looks like you're using Python 3.4 which comes with pip. pip is a tool for installing packages and any dependencies they might have (like the srting_types module from your error message). I'd suggest learning how to use it because it resolves most of the packaging problems with you needing to moving things around yourself. See an answer from a different question to learn more about pip.
There are some packages that need to be compiled. This can be difficult on Windows 7 if you don't have the proper toolchain set up to compile packages. I'd recommend Christoph Gohlke's wonderful collection of installable packages for Windows. You just need to make sure to grab the right version. Since 3.4 is still relatively new, some packages may not be available, so be warned.