Python 导入错误:没有名为“pandas.core.internals.managers”的模块;'pandas.core.internals' 不是一个包

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/54665527/
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-08-19 20:30:03  来源:igfitidea点击:

ImportError: No module named 'pandas.core.internals.managers'; 'pandas.core.internals' is not a package

pythonpandaspickle

提问by Fatih1923

When I tried to read a pickle file that saved by a former version of pandas, it yielded an ImportError.

当我试图读取由以前版本的熊猫保存的泡菜文件时,它产生了一个ImportError.

ImportError: No module named 'pandas.core.internals.managers'; 'pandas.core.internals' is not a package

导入错误:没有名为“pandas.core.internals.managers”的模块;'pandas.core.internals' 不是一个包

There was no hit on stackoverflow so i would like to share my solution for this particular problem.

stackoverflow 没有受到影响,所以我想分享我对这个特定问题的解决方案。

回答by Fatih1923

This error comes off due to encoding of formerly saved pickle file. If you updated pandas to newly amended version, it produces this import error.

由于以前保存的泡菜文件的编码,此错误消失。如果您将 pandas 更新为新修改的版本,则会产生此导入错误。

回答by Chandan

I was facing the same error when I was using pandas version 0.23.4.

我在使用 pandas version 时遇到了同样的错误0.23.4

I have installed pandas 0.24.1version explicitly by:

我已经0.24.1通过以下方式明确安装了熊猫版本:

pip3 install pandas==0.24.1

This solved my problem(Python version I was using was 3.5)

这解决了我的问题(我使用的 Python 版本是 3.5)

回答by Charles dc

I had the same problem, but for me, it seemed to come from the pickle package / interaction with the pandas package.

我有同样的问题,但对我来说,它似乎来自泡菜包/与熊猫包的交互。

I had Pandas version 0.23.4. I saved some pickle files with pandas.Dataframe.to_pickle, with python 3.6.6 & Pandas version 0.23.4. Then I upgraded to python 3.7.2 (Pandas version 0.23.4), and was enabled to read thoses pickle files with pandas.Dataframe.read_pickle. Next, I upgraded pandas to pandas 0.24.1, and it worked for me. I can read those files again.

我有 Pandas 版本 0.23.4。我pandas.Dataframe.to_pickle用 python 3.6.6 和 Pandas 版本 0.23.4保存了一些泡菜文件。然后我升级到 python 3.7.2(Pandas 版本 0.23.4),并且能够使用pandas.Dataframe.read_pickle. 接下来,我将 pandas 升级到 pandas 0.24.1,它对我有用。我可以再次读取这些文件。

回答by Bstampe

conda update pandas

conda update pandas

If you use conda package manager.

如果您使用 conda 包管理器。

回答by Gengyu Shi

Updating pandas would be the best solution for most cases. However if you have limitations updating your pandas version, and you need to consume pandas objects produced and pickled in a higher version, you can add class location map as below.

在大多数情况下,更新熊猫将是最佳解决方案。但是,如果您在更新 Pandas 版本时有限制,并且您需要使用在更高版本中生成和腌制的 Pandas 对象,您可以添加类位置图,如下所示。

from pandas.compat.pickle_compat import _class_locations_map

_class_locations_map.update({
    ('pandas.core.internals.managers', 'BlockManager'): ('pandas.core.internals', 'BlockManager')
})