Numpy.dtype has the wrong size, try recompiling
Asked Answered
O

3

17

When importing pandas I would get the following error:

Numpy.dtype has the wrong size, try recompiling

I am running Python 2.7.5, with Pandas 0.14.1, and Numpy 1.9.0. I have tried installing older versions of both using pip, with major errors every time. I am a beginner when it comes to Python so any help here would be much appreciated. :)

EDIT: running OS X 10.9.4

EDIT 2: here is a link to a video of me uninstalling and reinstalling Numpy + Pandas, and then running a .py file: https://www.dropbox.com/s/sx9l288jijokrar/numpy%20issue.mov?dl=0

Outing answered 26/9, 2014 at 20:18 Comment(12)
what os are you using?Millda
I am using OSX 10.9.4Outing
did you install pandas before you upgraded numpy?Millda
I tried both ways. Neither worked, and I believe numpy is installed with Pandas, no?Outing
I have numpy 1.9 and pandas 0.14.0 installed with no problems, have you tried uninstalling with pip and then reinstalling numpy and then pandas?Millda
also how did you install?Millda
I just tried exactly that and it still didn't work. :( Is there any other information I can give you that might be of help? Or should I try to log a bug?Outing
Installed using sudo pip install numpy and sudo pip install pandas==0.14.0Outing
Installing the most recent version of pandas (0.14.1) didn't work either.Outing
does sudo pip install -U numpy and sudo pip install -U pandas return Requirement already up-to-date:?Millda
Yes for numpy, currently no for Pandas as I had 0.14.0 installed. Tried to see if the two versions you had would work together. With both of them up-to-date I still am getting the same error when I try to import Pandas.Outing
Let us continue this discussion in chat.Outing
C
24

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.

Cartouche answered 28/3, 2015 at 19:1 Comment(1)
Thank you that fixed the problem also for me! I really have no clue why my python distribution used the numpy of the operating systems python distribution. However, now it works.Halo
B
7

I got same error. I solved by deleting existing numpy and reinstall again.

pip uninstall numpy #it will remove older version of  numpy on your computer
pip install numpy   #it will install recent version of numpy

Actually I don't have any idea why it works. I just changed numpy version.

Brett answered 28/3, 2016 at 8:11 Comment(0)
C
2

you should try to upgrade your numpy to latest. it worked for me.

pip install --upgrade numpy
Contradistinguish answered 21/8, 2016 at 9:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.