25

I have installed pandas on python 3.3, and coded like this:

import csv
import pandas
from pandas import DataFrame

csvdata = pandas.read_csv('datafile.csv')
df = DataFrame(csvdata)

It comes with the following error message:

cannot import name hashtable
Traceback (most recent call last):
  File "C:\Users\document\test4.py", line 5, in <module>
    import pandas
  File "C:\Python33\lib\site-packages\pandas\__init__.py", line 6, in <module>
    from . import hashtable, tslib, lib
ImportError: cannot import name hashtable

Could anyone help me figure out how to solve this error? Python and pandas were successfully installed.

Andy Hayden
  • 291,328
  • 80
  • 565
  • 500
sky404
  • 251
  • 1
  • 3
  • 3

5 Answers5

26

Update: I now recommend installing the scientific python stack using Anaconda.

Pandas comes bundled and can easily be updated using conda:

conda update pandas

It also comes bundled with cython, scipy (which is tricky to install via pip), statsmodels, and manages the dependencies/reationships between these packages for you.

It's worth emphaising that you don't need admin/sudo access to install it on the machine to install Anaconda.


If you're not using Anaconda, the recommended way to install pandas is via pip (on Mac and Windows):

pip install pandas

On Linux you can also install with python-pandas in whichever repository, but be aware you may be installing an older version of pandas, ideally you should be using the latest stable version.


It looks like you have tried to install from source, about which the docs mention:

Installing from the git repository requires a recent installation of Cython as the cythonized C sources are no longer checked into source control. Released source distributions will contain the built C files. I recommend installing the latest Cython via easy_install -U Cython

Note that you will not be able to import pandas if you open an interpreter in the source directory unless you build the C extensions in place:

python setup.py build_ext --inplace

Without compiling hashtables.pyx (and a few other cython files), pandas is unable to import them. These are required for pandas (which explains your error message).

Note: this error message has been made more descriptive for 0.11.1 onwards, it will say that the C-extensions were not built.

Andy Hayden
  • 291,328
  • 80
  • 565
  • 500
  • Thanks for letting me know, Andy. Honestly, I don't know where to start with your suggestion of "pip install pandas". Where and what application do I have to run with the text? Since I just started learning Python, I may need detailed/step-wise instruction. Please let me know how to. Thanks, – sky404 Jan 23 '13 at 07:37
  • @sky404 have you seen [this question](http://stackoverflow.com/questions/4750806/how-to-install-pip-on-windows)? Hope it can help! – Andy Hayden Jan 23 '13 at 07:39
  • 1
    I did install using pip, but still get the same error. I'm running a small web server using python and want to use pandas. The error will appear on my webpage. If I try "import pandas" from a local python prompt, I will get a different error: SyntaxError: future feature unicode_literals is not defined – danioyuan Feb 06 '13 at 01:51
  • 1
    Not sure if this would be useful for anyone, but using easy_install -U Cython instead of pip install Cython allowed me to install from source on Win 8.1 64 – sk8asd123 Dec 30 '13 at 20:26
  • I get this error message for `pip install pandas` on linux (fedora 20). – hobs Mar 26 '15 at 22:33
  • @hobs it may be preferable to install pandas via the fedora package https://admin.fedoraproject.org/pkgdb/package/python-pandas/. I now recommend using conda (much easier for the python data stack). – Andy Hayden Mar 27 '15 at 02:28
3

The pandas Python 3.3 binary here http://www.lfd.uci.edu/~gohlke/pythonlibs/ seems to have not been compiled successfully. I haven't had the time to configure my build machine to build and test Python 3.3 binaries but I do know that things work on Python 3.3 on the other platforms.

Wes McKinney
  • 83,626
  • 27
  • 133
  • 107
2

I had the same problem too when I tried installing pandas 0.13.1. It installed but I could not import it.

As @danioyuan suggests, I installed Cython using easy_install and now I am able to import pandas.

tro
  • 6,152
  • 5
  • 42
  • 63
KarthikS
  • 794
  • 8
  • 15
2

I have already tried all the stuff above, didn't work for me.

You can just change your version of pandas by

pip install --user pandas==0.22

only this worked for me:)

Yummy_Ou
  • 21
  • 2
0

I encountered the same problem. I installed pandas using command pip install pandas.

By default, my pip installed pandas in dist-packages of python3.2 and my default python version was 2.7. As a result when I did python to open the interactive shell and try to do

 import pandas

 File "<stdin>", line 1, in <module>
 File "/usr/local/lib/python3.2/dist-packages/pandas/__init__.py", line 6, in <module>
 from . import hashtable, tslib, lib
 ImportError: cannot import name hashtable

What solved my problem was:

 python3.2
 import pandas

Please check that the you use the same Python version whose dist-packages contain pandas.

arpiagar
  • 3,194
  • 1
  • 17
  • 12