简体   繁体   English

pandas ImportError:无法在Mac OS X上导入名称哈希表

[英]pandas ImportError: cannot import name hashtable on Mac OS X

I recently noticed I had an old version of pandas installed on my machine (0.10). 我最近发现我的机器上安装了旧版本的熊猫(0.10)。

I tried pip install -U first and got the error. 我先尝试了pip install -U并得到了错误。 I pip uninstalled, wiped any old directories, pip installed again and still the same error. 我将pip卸载,擦除了所有旧目录,再次安装pip仍然是相同的错误。 I even tried building from the git, but whatever I seem to do, I get the same error: 我什至尝试从git进行构建,但是无论我做什么,都会遇到相同的错误:

In [8]: import pandas
cannot import name hashtable
cannot import name hashtable
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-8-d6ac987968b6> in <module>()
----> 1 import pandas

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/__init__.py in <module>()
      5 
      6 try:
----> 7     from . import hashtable, tslib, lib
      8 except Exception:  # pragma: no cover
      9     import sys

/Users/kcampbell/pandas/tslib.pyx in init pandas.tslib (pandas/tslib.c:77195)()

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/pandas/__init__.py in <module>()
      5 
      6 try:
----> 7     from . import hashtable, tslib, lib
      8 except Exception:  # pragma: no cover
      9     import sys

ImportError: cannot import name hashtable

My numpy, pytz, python-dateutil are all up to date 我的numpy,pytz,python-dateutil都是最新的

In [1]: import numpy

In [2]: numpy.__version__
Out[2]: '1.9.1'

In [3]: import pytz

In [4]: pytz.__version__
Out[4]: '2014.9'

In [5]: import dateutil

In [6]: dateutil.__version__
Out[6]: '1.5'

When installing from pip, it is spitting out a bunch of stuff during what I guess is the build process. 从pip安装时,在我估计是构建过程中会吐出很多东西。 For example, this gets repeated a lot: 例如,这被重复很多次:

In file included from pandas/index.c:235:
pandas/src/numpy_helper.h:73:10: warning: static variable 'PyArray_API' is used in an inline function with external linkage [-Wstatic-in-inline]
  return PyArray_IsScalar(obj, Datetime);
         ^
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:49:35: note: expanded from
      macro 'PyArray_IsScalar'
        (PyObject_TypeCheck(obj, &Py##cls##ArrType_Type))
                                  ^
<scratch space>:84:1: note: expanded from here
PyDatetimeArrType_Type
^
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/include/numpy/__multiarray_api.h:1381:50: note: expanded from
      macro 'PyDatetimeArrType_Type'
#define PyDatetimeArrType_Type (*(PyTypeObject *)PyArray_API[215])
                                                 ^
/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/object.h:439:60: note: expanded from macro 'PyObject_TypeCheck'
    (Py_TYPE(ob) == (tp) || PyType_IsSubtype(Py_TYPE(ob), (tp)))
                                                           ^
pandas/src/numpy_helper.h:71:1: note: use 'static' to give inline function 'is_datetime64_object' internal linkage
PANDAS_INLINE int
^
static 
pandas/src/helper.h:6:27: note: expanded from macro 'PANDAS_INLINE'
    #define PANDAS_INLINE __inline__
                          ^
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/include/numpy/__multiarray_api.h:812:15: note: 'PyArray_API'
      declared here
static void **PyArray_API=NULL;

I've run python and ipython from different directories to test the "Can't run from source directory" idea. 我已经从不同的目录运行python和ipython来测试“无法从源目录运行”的想法。 At this point I'm out of things to try. 在这一点上,我无法尝试。 I do have Cython installed for when I tried to install from the git. 当我尝试从git安装时,确实安装了Cython。 I did previously have an anaconda install that I got rid of, so I'm fairly sure I don't have any stray installs lying around somewhere? 我以前确实有摆脱过的anaconda安装,所以我很确定自己附近没有任何流浪安装?

I'm at a loss at this point. 我现在不知所措。 Any help would be greatly appreciated. 任何帮助将不胜感激。 Thanks! 谢谢!

OK, the problem was that your pandas installation was screwed up. 好的,问题是您的熊猫安装被搞砸了。

The most likely reason for this is that you were inside a directory named pandas when you did the pip install pandas , which caused some of the build steps to pick up relative paths to the local directory instead of paths to the temporary directory where the build happens. 造成这种情况的最可能原因是,当您执行pip install pandas pandas时,您位于名为pandas的目录中,这导致一些构建步骤选择了本地目录的相对路径,而不是构建发生位置的临时目录的路径。 。 Of course that shouldn't happen, but with a build based on custom Python and Cython code as complicated as Pandas, it's not all that surprising. 当然,这不应该发生,但是基于Pandas这样复杂的基于自定义Python和Cython代码的构建,这并不令人惊讶。 If you could reproduce the problem, I'd file a bug upstream, but I'm guessing that wouldn't be easy. 如果您可以重现该问题,则可以向上游提交一个错误,但我猜测这并非易事。

Anyway, whatever the reason, the solution is the same: uninstall it, then make sure you're in a directory that isn't named pandas and doesn't have anything named pandas in it, then reinstall. 无论如何,无论出于何种原因,解决方案都是相同的:卸载它,然后确保您位于一个未命名为pandas且目录中没有任何命名为pandas中,然后重新安装。

I had so much trouble getting c-based modules to work/compile on my mac, until someone pointed me at MacPorts https://www.macports.org/ - in my opinion it's a well supported, up-to-date package delivery system that serves python really well - some of the more obscure packages aren't provided, but I've not come across a mainstream one yet that's not supported. 在基于c的模块上在Mac上运行/编译时,我遇到了很多麻烦,直到有人将我指向MacPorts https://www.macports.org/为止-在我看来,这是一个受到良好支持的最新软件包交付方式能够很好地服务python的系统-没有提供一些比较晦涩的软件包,但是我还没有遇到主流的软件包,但是不支持。

I just checked and cython is part of the supported packages. 我刚刚检查了一下,cython是受支持软件包的一部分。

port search cython

...various flavours of cython found for differing versions of python...
...including...

py34-cython @0.21.1 (python, devel)
A language for writing C extension modules for Python.

So not a direct answer, I know, but maybe something worth trying? 我知道这不是一个直接的答案,但是也许值得尝试?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM