Mac OS X 上的 Pandas 安装:ImportError(无法导入名称哈希表)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14568070/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 20:37:19  来源:igfitidea点击:

Pandas installation on Mac OS X: ImportError (cannot import name hashtable)

pythonhashtablepandascythonimporterror

提问by Emily Chen

I would like to build pandas from source rather than use a package manager because I am interested in contributing. The first timeI tried to build pandas, these were the steps I took:

我想从源代码构建Pandas而不是使用包管理器,因为我有兴趣做出贡献。我第一次尝试构建 Pandas 时,我采取了以下步骤:

1) created the virtualenv mkvirtualenv --no-site-packages pandas

1)创建了virtualenv mkvirtualenv --no-site-packages pandas

2) activated the virtualenv

2)激活virtualenv

3) installed Anaconda CE. However, this was installed in ~/anaconda.

3)安装Anaconda CE。但是,它安装在 ~/anaconda 中。

4) cloned pandas

4) 克隆Pandas

5) built C extensions in place

5) 就地构建 C 扩展

(pandas)ems ~/.virtualenvs/pandas/localrepo/pandas> ~/anaconda/bin/python setup.py build_ext --inplace

(pandas)ems ~/.virtualenvs/pandas/localrepo/pandas> ~/anaconda/bin/python setup.py build_ext --inplace

6) built pandas

6) 构建Pandas

(pandas)ems ~/.virtualenvs/pandas/localrepo/pandas> ~/anaconda/bin/python setup.py build

(pandas)ems ~/.virtualenvs/pandas/localrepo/pandas> ~/anaconda/bin/python setup.py build

7) ran nosetests on master branch

7)在主分支上运行鼻子测试

Tests failed: (pandas)ems ~/.virtualenvs/pandas/localrepo/pandas> nosetests pandas E ====================================================================== ERROR: Failure: ValueError (numpy.dtype has the wrong size, try recompiling) ---------------------------------------------------------------------- Traceback (most recent call last): File "/Users/EmilyChen/.virtualenvs/pandas/lib/python2.7/site-packages/nose/loader.py", line 390, in loadTestsFromName addr.filename, addr.module) File "/Users/EmilyChen/.virtualenvs/pandas/lib/python2.7/site-packages/nose/importer.py", line 39, in importFromPath return self.importFromDir(dir_path, fqname) File "/Users/EmilyChen/.virtualenvs/pandas/lib/python2.7/site-packages/nose/importer.py", line 86, in importFromDir mod = load_module(part_fqname, fh, filename, desc) File "/Users/EmilyChen/.virtualenvs/pandas/localrepo/pandas/pandas/init.py", line 6, in from . import hashtable, tslib, lib File "numpy.pxd", line 156, in init pandas.hashtable (pandas/hashtable.c:20354) ValueError: numpy.dtype has the wrong size, try recompiling

测试失败:(pandas)ems ~/.virtualenvs/pandas/localrepo/pandas> 鼻子测试Pandas E ============================ ======================================== 错误:失败:ValueError (numpy.dtype大小不对,重新编译试试) ------------------------------------------ ------------------------------ 回溯(最近一次调用最后一次):文件“/Users/EmilyChen/.virtualenvs/pandas/lib/ python2.7/site-packages/nose/loader.py", line 390, in loadTestsFromName addr.filename, addr.module) 文件“/Users/EmilyChen/.virtualenvs/pandas/lib/python2.7/site-packages/鼻子/importer.py”,第 39 行,在 importFromPath 中返回 self.importFromDir(dir_path, fqname) 文件“/Users/EmilyChen/.virtualenvs/pandas/lib/python2.7/site-packages/nose/importer.py”,第 86 行,在 importFromDir mod = load_module(part_fqname, fh, filename, desc) File "/Users/EmilyChen/.virtualenvs/pandas/localrepo/pandas/pandas/init.py", line 6, in from . import hashtable, tslib, lib File "numpy.pxd", line 156, in init pandas.hashtable (pandas/hashtable.c:20354) ValueError: numpy.dtype has the wrong size ,尝试重新编译



Ran 1 test in 0.001s

在 0.001 秒内运行 1 次测试

FAILED (errors=1)

失败(错误=1)

Someone on the PyData mailing list said:

PyData 邮件列表上有人说:

It looks like you have NumPy installed someplace else on your machine and AnacondaCE is not playing nicely in the virtualenv. The error you are getting is a Cython error message which occurs when the NumPy version it built against doesn't match the installed version on your system-- I had thought that 1.7.x was supposed to be ABI compatible with 1.6.x (so this would not happen) but I guess not. Sigh

看起来您在机器上的其他地方安装了 NumPy,而 AnacondaCE 在 vi​​rtualenv 中运行不佳。您收到的错误是 Cython 错误消息,当它针对它构建的 NumPy 版本与您系统上安装的版本不匹配时会发生该错误 - 我曾认为 1.7.x 应该与 1.6.x ABI 兼容(所以这不会发生)但我想不会。叹

The numpy version in Anaconda CE library is 1.7.0b2 and my system numpy installation is version 1.5.1. Setup.py linked to the numpy in the Anaconda distribution's libraries when it built pandas but my guess is it's linking to my system version when nosetests runs /pandas/init.py

Anaconda CE 库中的 numpy 版本是 1.7.0b2,我的系统 numpy 安装版本是 1.5.1。Setup.py 在构建 Pandas 时链接到 Anaconda 发行版库中的 numpy,但我的猜测是当鼻子测试运行 /pandas/ init.py时它链接到我的系统版本

Next, I repeated the steps outside a virtualenv, but got the same error. Finally, I decided to install all the dependencies in a new virtualenv instead of using the Anaconda distribution to build pandas. This way, I can see that dependencies like numpy reside in the lib directory of the virtualenv python installation, which takes precedent when pandas.initruns import statements. This is what I did:

接下来,我在 virtualenv 之外重复了这些步骤,但得到了同样的错误。最后,我决定在一个新的 virtualenv 中安装所有依赖项,而不是使用 Anaconda 发行版来构建 Pandas。这样我就可以看到numpy之类的依赖存在于virtualenv python安装的lib目录下,pandas. init运行导入语句。这就是我所做的:

1) installed numpy, dateutil, pytz, cython, scipy, matplotlib and openpyxl using pip

1) 使用 pip 安装 numpy、dateutil、pytz、cython、scipy、matplotlib 和 openpyxl

2) built c extensions in place

2) 就地构建 c 扩展

3) pandas install output here: http://pastebin.com/3CKf1f9i

3) Pandas在这里安装输出:http: //pastebin.com/3CKf1f9i

4) pandas did not install correctly

4)pandas没有正确安装

(pandas)ems ~/.virtualenvs/pandas/localrepo/pandas> python
Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas
 cannot import name hashtable
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pandas/__init__.py", line 6, in <module>
from . import hashtable, tslib, lib
ImportError: cannot import name hashtable

I took a look at this questionbut cython installed in my case, and I am trying to build successfully from source rather than using pip like the answer recommended..

我看了一下这个问题,但是在我的情况下安装了 cython,我试图从源代码成功构建,而不是像推荐的答案那样使用 pip ..

(pandas)ems ~/.virtualenvs/pandas/localrepo/pandas> which cython
/Users/EmilyChen/.virtualenvs/pandas/bin/cython

回答by Garrett

I've received the same error (ImportError: cannot import name hashtable) when trying to import pandas from the source code directory. Try starting the python interpreter from a different directory and import pandas again.

ImportError: cannot import name hashtable尝试从源代码目录导入Pandas时,我收到了相同的错误 ( )。尝试从不同的目录启动 python 解释器并再次导入 pandas。