如何在pycharm中解决pandas导入错误?

时间:2018-03-15 19:03:16

标签: python pandas pycharm

我已经从终端安装了pandas,并在pycharm项目解释器中添加了pandas。但是,每次我运行使用pandas的程序时,它都会一直提醒我错误。

RuntimeError: module compiled against API version 0xb but this version of numpy is 0xa
Traceback (most recent call last):
  File "/Users/Rabbit/PycharmProjects/NLP/review2vector.py", line 7, in <module>
    from pandas import DataFrame
  File "/Users/Rabbit/Library/Python/2.7/lib/python/site-packages/pandas/__init__.py", line 35, in <module>
    "the C extensions first.".format(module))
ImportError: C extension: numpy.core.multiarray failed to import not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace --force' to build the C extensions first.

我也按照这个问题的回答How to solve import error for pandas?但它对我不起作用。

2 个答案:

答案 0 :(得分:1)

如果您使用虚拟环境来安装和维护Python包,则可以轻松避免这些问题。有关详细信息,请参阅此处的链接:LINK

答案 1 :(得分:1)

错误消息告诉您numpy未完全安装。没有足够的信息来猜测具体是什么问题,但如果我正在排除故障,我会使用我的软件包管理器(可能是pip)卸载然后重新安装numpy和pandas。我会单独做numpy,以便我可以看到消息。 numpy页面说他们应该有预编译的轮子,所以它看起来像版本不匹配。

Pycharm允许您轻松地将软件包安装到virtualenv中并确保在打开pycharm终端时始终激活env(太棒了!)但是它也很难注意到安装错误。