Pandas 导入:ModuleNotFoundError:没有名为“pandas._libs.tslib”的模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50089668/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 05:30:50  来源:igfitidea点击:

Pandas Import : ModuleNotFoundError: No module named 'pandas._libs.tslib'

pythonpython-3.xpandas

提问by ISHAN BOSE

Whenever I try to import pandas, whether inside a virtualenv or otherwise I am always getting this error.

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

I tried the follwoing solutions:

我尝试了以下解决方案:

  1. Cloning pandas from git and running SETUP.py (on an instance of python 3.6 installed directly into my win10 os)
  2. Using anaconda as python distribution and conda to install pandas
  3. Updating microsoft visual c++ 2017 redistributable
  4. Updating C:\ProgramData\Anaconda3\Lib\site-packages\PyInstaller\hooks\hook-pandas.py
  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

None of these seem to work. Please help me understand what the issue here is.

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

回答by Andy Hayden

This exception:

这个例外:

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

suggests that pandas was not built properly during installation.

表明在安装过程中Pandas没有正确构建。

The latter sentence:

后一句:

If you want to import pandas from the source directory, you may need to run python setup.py build_ext --inplace --forceto build the C extensions first

如果要从源目录导入pandas,可能需要先运行python setup.py build_ext --inplace --force以构建C 扩展

Is really only something you ought to be doing if you are contributing to pandas source code (e.g. to fix a pandas bug or add a feature to pandas itself) to the pandas-dev github repository*.
Most likely you shouldn't be building from sourcein your project.

如果您将 Pandas 源代码(例如修复 Pandas 错误或向 Pandas 本身添加功能)贡献到Pandas-dev github 存储库,这真的只是您应该做的事情。
很可能您不应该在项目中从源代码构建

Generally anaconda is pretty good at installing pandas correctly, and so my guess/comment was:

一般来说,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\Python36and see if that helps

我的猜测是虚拟环境没有使用 anaconda,并且 Pandas 的安装搞砸了(可能是在安装 anaconda 之前创建的?)。我会删除这个目录C:\Users\ishan\AppData\Roaming\Python\Python36,看看是否有帮助

The reason I suggested that directory was because it was in the error message AND it doesn't look like somewhere I expect anaconda's installation of pandas to be (either generally or as a virtualenv).

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



* Note: this is something fun to do, to give back to the pandas community: there's some low-hanging fruit, typos or code changes, so I recommend investigating whether there's any way you can contribute.

* 注意:这是一件很有趣的事情,为了回馈 Pandas 社区:有一些简单的结果、错别字或代码更改,所以我建议调查是否有任何方式可以做出贡献。

回答by Jacob Kalakal Joseph

If you are using a Conda distribution (e.g., AnaConda, MiniConda), as it seems to be the case, uninstalling and reinstalling Pandas may help.

如果您使用的是 Conda 发行版(例如 AnaConda、MiniConda),似乎是这种情况,卸载并重新安装 Pandas 可能会有所帮助。

Run the following commands on the cmd console:

在 cmd 控制台运行以下命令:

conda uninstall pandas

conda install pandas

回答by Beibian Ren

I run into same error when setting up python, keras and anything between. Background: I installed anaconda and followed instructions by https://www.youtube.com/watch?v=z0qhKP2liHsand instruction to downgrade to python 3.6 by http://docs.anaconda.com/anaconda/user-guide/faq/#how-do-i-get-the-latest-anaconda-with-python-3-5

我在设置 python、keras 和两者之间的任何东西时遇到了同样的错误。背景:我安装了 anaconda 并按照https://www.youtube.com/watch?v=z0qhKP2liHs 的说明和http://docs.anaconda.com/anaconda/user-guide/faq/ 的说明降级到 python 3.6 #how-do-i-get-the-latest-anaconda-with-python-3-5

Running from Jupyter I run into same problem as author I was able to solve my problem by: - uploading pandas version for python 3.6 per https://docs.anaconda.com/anaconda/packages/py3.6_win-64/

从 Jupyter 运行我遇到了与作者相同的问题我能够通过以下方式解决我的问题: - 上传 python 3.6 的 Pandas 版本每个https://docs.anaconda.com/anaconda/packages/py3.6_win-64/

  • then I run python from command line .. it worked

  • then I tested with PyCharm .. it worked

  • 然后我从命令行运行 python .. 它有效

  • 然后我用 PyCharm 进行了测试 .. 它有效

Appears that either Anaconda&Jupyter combination did not work or selecting pandas version did the job.

似乎 Anaconda 和 Jupyter 组合不起作用或选择Pandas版本完成了这项工作。

回答by maneesha gara

since tslib has been deprecated for the latest version of pandas. try to remove the pd.tslib.Dataframe and replace with pd.DataFrame where ever tslib is present in ggplot library. it works !!

因为 tslib 已被最新版本的 Pandas 弃用。尝试删除 pd.tslib.Dataframe 并用 pd.DataFrame 替换 ggplot 库中存在 tslib 的地方。有用 !!

you can find the packages in the lib file of ggplot folder.

您可以在 ggplot 文件夹的 lib 文件中找到这些包。

Thank you!

谢谢!