导入熊猫时C扩展错误

时间:2018-12-10 21:37:52

标签: python python-3.x pandas

我知道有很多与此相关的问题,但是没有人为我解答,因为它们都使用Anaconda或Unix环境。

我安装了适用于Windows 7的Python 3.7.1,以及带有pip的pandas 0.23.4。因此,我只做import pandas as pd(通过jupyter和console),它吐出了

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
c:\users\4217109\appdata\local\programs\python\python37-32\lib\site-packages\pandas\__init__.py in <module>
     25 try:
---> 26     from pandas._libs import (hashtable as _hashtable,
     27                              lib as _lib,

c:\users\4217109\appdata\local\programs\python\python37-32\lib\site-packages\pandas\_libs\__init__.py in <module>
      3 
----> 4 from .tslib import iNaT, NaT, Timestamp, Timedelta, OutOfBoundsDatetime
      5 

ImportError: cannot import name 'iNaT' from 'pandas._libs.tslib' (unknown location)

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
<ipython-input-2-3d5cd439516e> in <module>
----> 1 import pandas as pd
      2 from datetime import date, datetime
      3 import calendar

c:\users\4217109\appdata\local\programs\python\python37-32\lib\site-packages\pandas\__init__.py in <module>
     33                       "pandas from the source directory, you may need to run "
     34                       "'python setup.py build_ext --inplace --force' to build "
---> 35                       "the C extensions first.".format(module))
     36 
     37 from datetime import datetime

ImportError: C extension: 'iNaT' from 'pandas._libs.tslib' (unknown location) 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.

谁能告诉我如何克服这个问题?错误消息的提示可能听起来很明显,但我只是不明白,所以如果有人一步一步地解释它,我将不胜感激。

1 个答案:

答案 0 :(得分:0)

按照从github克隆的熊猫上建议的setup.com过程进行操作。 这需要pip --update的Cython。 (site_packages / pandas中没有setup.com)。
然后,我卸载并重新安装了熊猫。 高兴地报告已解决问题!