Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

python 3.x - Importing pandas shows ImportError: cannot import name hashtable

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:Usersdocumentest4.py", line 5, in <module>
    import pandas
  File "C:Python33libsite-packagespandas\__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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...