每当我试图导入熊猫,无论是在虚拟环境中还是在其他地方,我总是得到这个错误。
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.
我尝试了以下解决方案:
这些似乎都不管用。请帮助我理解这里的问题是什么。
此例外情况:
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
说明熊猫在安装过程中未正确建造。
后一句:
如果您想从源代码目录导入熊猫,您可能需要运行Pythonsetup.pybuild_ext--inplace--force来首先构建C扩展
如果您正在将pandas源代码(例如修复pandas bug或向pandas本身添加功能)添加到pandas dev github存储库*,那么这确实是您应该做的事情
最有可能的情况是,您不应该在项目中从源代码进行构建。
一般来说,anaconda非常擅长正确安装熊猫,因此我的猜测/评论是:
我的猜测是虚拟环境没有使用anaconda,熊猫的安装被搞砸了(也许是在安装anaconda之前创建的?)。我会删除这个目录C:\用户\Mountain\AppData\漫游\Python\Python36
,看看这是否有帮助
我之所以建议使用该目录,是因为它出现在错误消息中,而且它看起来不像我所期望的anaconda安装pandas的地方(无论是一般安装还是虚拟安装)。
*注:这是一件很有趣的事情,回馈熊猫社区:有一些很容易解决的问题、拼写错误或代码更改,所以我建议调查一下是否有任何方法可以帮助他们。
如果您使用的是Conda发行版(如AnaConda、MiniConda),那么卸载和重新安装Pandas可能会有所帮助。
在cmd控制台上运行以下命令:
conda uninstall pandas
conda install pandas
我在设置python、keras和任何介于两者之间的东西时遇到了相同的错误。背景:我安装了anaconda并按照说明操作https://www.youtube.com/watch?v=z0qhKP2liHs以及通过http://docs.anaconda.com/anaconda/user-guide/faq/#how-do-i-get-latest-anaconda-with-python-3-5
从Jupyter运行,我遇到了与作者相同的问题,我能够通过以下方式解决我的问题:-上传Python 3.6的熊猫版本https://docs.anaconda.com/anaconda/packages/py3.6_win-64/
>
然后我测试了PyCharm...它的工作
看来要么是蟒蛇