Pandas: Unable to import pandas

Created on 20 Jun 2014  路  12Comments  路  Source: pandas-dev/pandas

I've installed pandas using pip. I got the following versions of pip and numpy:

pvadrevu@MacPro~$ sudo pip freeze|grep pandas
pandas==0.14.0
pvadrevu@MacPro~$ sudo pip freeze|grep numpy
numpy==1.8.1

I am using this on OSX 10.9.2. I get the following error when trying to import pandas

numpy.dtype has the wrong size, try recompiling
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/pandas/__init__.py", line 6, in <module>
    from . import hashtable, tslib, lib
  File "numpy.pxd", line 157, in init pandas.hashtable (pandas/hashtable.c:22331)
ValueError: numpy.dtype has the wrong size, try recompiling
Build

Most helpful comment

@Henry2012 @nspies @maxiaojun @phani-vadrevu

couple of points

  • installation with pip has come up multiple times in various forms: #3362 #3711 #7486 #3471 #3074.
  • using sudo to pip install things is a terrible idea. Instead, I suggest using virtualenv, miniconda or anaconda to set up environments that let you sandbox things so that e.g., you don't clobber your system's python libraries. They also mostly prevent you from having to deal with annoying issues like these.
  • not being able to import pandas is not really a pandas issue.
    if you clobber your installation of numpy and/or pandas because you sudo pip installed pandas and e.g., then you change the numpy version on your machine and now you can't import pandas, there's not a whole lot the pandas devs can do for you.

that said, i'm happy to help someone set up an environment using any of the above tools, but trying to track down the reason as to how/why/when you clobbered something is an exercise in futility.

FWIW, I'm also running 3 versions of Windows, Arch Linux, and Mac OS X 10.9.5 and I've yet to run into this problem using any of the above mentioned tools. Also, if you ever need to work on a machine that's not your own and you don't have sudo privileges then you won't be able to install anything. Avoid sudo pip install <package> at all costs, especially since there are easier, more robust ways of handling packaging.

All 12 comments

pip will sometimes install/upgrade dependencies in an arbitrary order. This error message indicates that pandas was built against an older version of numpy. If you reinstall pandas it should go away.

I did try uninstalling pandas and reinstalling it. But I get the same error again.

Compiling pandas from source seems to work though. Only pip installation produces the above error for me.

I posted an answer on what works for me in the first question (installing from source). But for some reason, I cannot get to install it using pip.

@phani-vadrevu Following your instructions, I can import pandas finally.

  1. updated numpy to 1.9.0 using "sudo easy_install -U numpy" (while "sudo pip install -U numpy" did nothing but keep the old version)
  2. checked whether numpy was updated to the latest version
  3. updated pandas to the latest version using easy_install
  4. checked whether importing pandas works.
  5. done.

+1 works for me! Thank you!

I can confirm that pip is installing numpy 1.6.2 and that using easy_install to upgrade bumpy to 1.9.0 makes the pip pandas installation work properly. I'm not sure why pip isn't installing the most recent version of numpy, but the easy_install workaround works, as does installing pandas from source (the pip install doesn't actually seem to work against numpy 1.6.2).

Same error with both numpy and pandas being latest versions:

$ pip freeze | egrep 'numpy|pandas'
numpy==1.9.0
pandas==0.14.1

@Henry2012 @nspies @maxiaojun @phani-vadrevu

couple of points

  • installation with pip has come up multiple times in various forms: #3362 #3711 #7486 #3471 #3074.
  • using sudo to pip install things is a terrible idea. Instead, I suggest using virtualenv, miniconda or anaconda to set up environments that let you sandbox things so that e.g., you don't clobber your system's python libraries. They also mostly prevent you from having to deal with annoying issues like these.
  • not being able to import pandas is not really a pandas issue.
    if you clobber your installation of numpy and/or pandas because you sudo pip installed pandas and e.g., then you change the numpy version on your machine and now you can't import pandas, there's not a whole lot the pandas devs can do for you.

that said, i'm happy to help someone set up an environment using any of the above tools, but trying to track down the reason as to how/why/when you clobbered something is an exercise in futility.

FWIW, I'm also running 3 versions of Windows, Arch Linux, and Mac OS X 10.9.5 and I've yet to run into this problem using any of the above mentioned tools. Also, if you ever need to work on a machine that's not your own and you don't have sudo privileges then you won't be able to install anything. Avoid sudo pip install <package> at all costs, especially since there are easier, more robust ways of handling packaging.

Right now i had the same issue. If you are using Virtual Env and you install pandas, you have to deactivate the env. After you activate it again it should work. 馃帀

I am on windows 10 python 3.8 and this error message occurs:
Traceback (most recent call last):
File "", line 1, in
import pandas
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38-32\lib\site-packagespandas__init__.py", line 55, in
from pandas.core.api import (
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38-32\lib\site-packagespandas\core\api.py", line 29, in
from pandas.core.groupby import Grouper, NamedAgg
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38-32\lib\site-packagespandas\core\groupby__init__.py", line 1, in
from pandas.core.groupby.generic import DataFrameGroupBy, NamedAgg, SeriesGroupBy
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38-32\lib\site-packagespandas\core\groupby\generic.py", line 60, in
from pandas.core.frame import DataFrame
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38-32\lib\site-packagespandas\core\frame.py", line 124, in
from pandas.core.series import Series
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38-32\lib\site-packagespandas\core\series.py", line 4572, in
Series._add_series_or_dataframe_operations()
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38-32\lib\site-packagespandas\core\generic.py", line 10349, in _add_series_or_dataframe_operations
from pandas.core.window import EWM, Expanding, Rolling, Window
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38-32\lib\site-packagespandas\core\window__init__.py", line 1, in
from pandas.core.window.ewm import EWM # noqa:F401
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38-32\lib\site-packagespandas\core\window\ewm.py", line 5, in
import pandas._libs.window.aggregations as window_aggregations
ImportError: DLL load failed while importing aggregations: The specified module could not be found.

@AaryamanCodes see https://github.com/pandas-dev/pandas/issues/32857, which is reporting a similar error. Can you share information on how you installed pandas over there?

Was this page helpful?
0 / 5 - 0 ratings