如何在Windows上使用iPython Notebook解决pandas导入错误?

6

我正在使用iPython并尝试导入pandas库,我的主要目的是使用XLwings。

我使用Anaconda在Windows 7上安装了Python、pandas以及相关依赖。

以下是我的代码:

from pandas import DataFrame

这将会得到:

ImportError                               Traceback (most recent call last)
<ipython-input-7-26dfcabfb474> in <module>()
----> 1 from pandas import DataFrame

C:\Users\Accounting\Anaconda\lib\site-packages\pandas\__init__.py in <module>()
     11                       "pandas from the source directory, you may need to run "
     12                       "'python setup.py build_ext --inplace' to build the C "
---> 13                       "extensions first.".format(module))
     14 
     15 from datetime import datetime

ImportError: C extension: hashtable not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace' to build the C extensions first.

有没有使用Python/pandas在Windows下的iPython中有经验的人可以帮助我理解如何解决这个错误?

具体来说,我应该在哪里运行“python setup.py build_ext --inplace”?

谢谢!


2
你不需要这样做。在旧版本(conda)中存在一个错误,如果您在使用pandas时更新它,则无法正确更新。尝试关闭所有Python进程,然后运行“conda remove pandas; conda install pandas”。 - Jeff
糟糕!那个完美地运行了!谢谢Jeff。 - Greg Carter
2个回答

8

如Jeff在评论中发布的:

旧版本(conda)存在一个bug,如果您在使用过程中更新了pandas,它不会正确地更新。尝试关闭所有Python进程,然后

conda remove pandas

conda install pandas

我在Ubuntu 14.04中遇到了这个问题,关闭Python进程,conda remove pandas然后重新安装似乎无法解决它。重新安装(使用conda)后,我得到了这个错误信息:“ImportError: C extension: No module named builtins not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace' to build the C extensions first." - ely

0

我发现在安装包(大多数来自Christoph Gohlke)时,有时必须使用“pip install name of .whl”(在正确的包路径下),并最初将“C:/miscutilities”添加到环境变量PATH中,如果它无法从Anaconda -> Lib -> site-packages安装。然后我使用了一些其他的conda包。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接