每当我尝试导入 pandas 时,无论是在 virtualenv 中还是在其他地方,我总是会收到此错误。
Python 3.6.2 |Anaconda custom (64-bit)| (default, Sep 19 2017, 08:03:39) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas as pd
Traceback (most recent call last):
File "C:\Users\ishan\AppData\Roaming\Python\Python36\site-packages\pandas__init__.py", line 26, in <module>
from pandas._libs import (hashtable as _hashtable,
File "C:\Users\ishan\AppData\Roaming\Python\Python36\site-packages\pandas_libs__init__.py", line 3, in <module>
from .tslib import iNaT, NaT, Timestamp, Timedelta, OutOfBoundsDatetime
ModuleNotFoundError: No module named 'pandas._libs.tslib'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\ishan\AppData\Roaming\Python\Python36\site-packages\pandas__init__.py", line 35, in <module>
"the C extensions first.".format(module))
ImportError: C extension: No module named 'pandas._libs.tslib' 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.
我尝试了以下解决方案:
- 从 git 克隆 pandas 并运行 SETUP.py(在直接安装到我的 win10 操作系统中的 python 3.6 实例上)
- 使用 anaconda 作为 python 发行版和 conda 安装 pandas
- 更新 Microsoft Visual C++ 2017 Redistributable
- 更新 C:\ProgramData\Anaconda3\Lib\site-packages\PyInstaller\hooks\hook-pandas.py
这些似乎都不起作用。请帮助我了解这里的问题是什么。
原文由 ISHAN BOSE 发布,翻译遵循 CC BY-SA 4.0 许可协议
如果您使用的是 Conda 发行版(例如,AnaConda、MiniConda),似乎是这种情况,卸载并重新安装 Pandas 可能会有所帮助。
在cmd控制台运行以下命令: