gpt4 book ai didi

python - Pandas 导入 : ModuleNotFoundError: No module named 'pandas._libs.tslib'

转载 作者:行者123 更新时间:2023-11-28 17:07:33 42 4
gpt4 key购买 nike

每当我尝试导入 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.

我尝试了以下解决方案:

  1. 从 git 克隆 pandas 并运行 SETUP.py(在直接安装到我的 win10 操作系统中的 python 3.6 实例上)
  2. 使用 anaconda 作为 python 发行版并使用 conda 安装 pandas
  3. 更新 Microsoft Visual C++ 2017 可再发行版
  4. 更新 C:\ProgramData\Anaconda3\Lib\site-packages\PyInstaller\hooks\hook-pandas.py

这些似乎都不起作用。请帮助我了解这里的问题是什么。

最佳答案

这个异常:

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

提示 pandas 在安装过程中没有正确构建。

后一句:

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

如果您为 pandas 源代码做出贡献(例如,修复 pandas 错误或向 pandas 本身添加功能),这实际上只是您应该做的事情 pandas-dev github repository *.
您很可能不应该在您的项目中从源代码构建

通常 anaconda 非常擅长正确安装 pandas,所以我的猜测/评论是:

My guess is the virtual env is not using anaconda, and the install of pandas is messed up (perhaps created before installing anaconda?). I would delete this directory C:\Users\ishan\AppData\Roaming\Python\Python36 and see if that helps

我建议该目录的原因是因为它在错误消息中并且它看起来不像我期望的 anaconda 安装 pandas 的地方(通常或作为 virtualenv)。


* 注意:这是一件有趣的事情,可以回馈 pandas 社区:有一些唾手可得的成果、拼写错误或代码更改,因此我建议调查您是否可以通过任何方式做出贡献。

关于python - Pandas 导入 : ModuleNotFoundError: No module named 'pandas._libs.tslib' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50089668/

42 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com