Valueerror: Numpy.Dtype Has the Wrong Size, Try Recompiling

sklearn numpy.dtype has the wrong size, try recompiling in both pycharm and terminal

The error "numpy.dtype has the wrong size, try recompiling" means that sklearn was compiled against a numpy more recent than the numpy version sklearn is now trying to import. To fix this, you need to make sure that sklearn is compiled against the version of numpy that it is now importing, or an earlier version. See ValueError: numpy.dtype has the wrong size, try recompiling for a detailed explanation.

I guess from your paths that you are using the OSX system Python (the one that ships with OSX, at /usr/bin/python). Apple has modified this Python in a way that makes it pick up its own version of numpy rather than any version that you install with pip etc - see https://github.com/MacPython/wiki/wiki/Which-Python#system-python-and-extra-python-packages . I strongly recommend you switch to Python.org or homebrew Python to make it easier to work with packages depending on numpy.

Numpy.dtype has the wrong size, try recompiling

I've seen this error before and it typically does have to do with pandas referencing an old version of numpy. But reinstalling may not help if your python path is still pointing to an old version of numpy.

When you install numpy via pip, pip will tell you where it was installed. Something like

pip install numpy==1.9.2
Requirement already satisfied (use --upgrade to upgrade): numpy==1.9.2 in /Library/Python/2.7/site-packages
Cleaning up...

So you have the correct version of numpy installed. But when you go into python

$ python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> numpy.__file__
'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/__init__.pyc'
>>> numpy.version.version
'1.8.0rc1'

Your path might be pointing at a different numpy.

Easiest solution I've found for this is simply to remove the unwanted version of numpy (moving it to a _bak folder for safety)

mv /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy_bak

And now when I start python

$ python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> numpy.__file__
'/Library/Python/2.7/site-packages/numpy/__init__.pyc'
>>> numpy.version.version
'1.9.2'

I've got the version I want.

For more complex workflows where different applications might need different versions of various packages, virtualenvs are a great way to go http://docs.python-guide.org/en/latest/dev/virtualenvs/. But I think for your case where you just want pandas and numpy to play nice, this approach should work fine.

pandas ValueError: numpy.dtype has the wrong size, try recompiling

You can install previous version of pandas.

pip uninstall numpy
pip uninstall pandas
pip install pandas==0.13.1

In my situation it solved problem...

numpy.ufunc has the wrong size, try recompiling. even with the latest pandas and numpy versions

The answer was that fastparquet (a package that is used by pandas) was using numpy older binary file for some reason.

Updating that package helped. I guess that if someone else comes around this problem, to try and update all the related packages (that use numpy) will be the right way to go



Related Topics



Leave a reply



Submit