导入聚合时出现 DLL 加载失败错误: 找不到指定的模块。

13

我是Python的新手,目前在导入一些库时遇到了麻烦。

我正在使用Python 3.8。

我已经在CMD中使用"pip install pandas"安装了Pandas。

如果我进入Python文件夹,我会看到Pandas已经被安装:

C:\Users\VALENTINA\AppData\Local\Programs\Python\Python38-32\Lib\site-packages

但是当我尝试在我的脚本中导入Pandas时,我会收到这个错误消息:

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    import pandas as pd
  File "C:\Users\VALENTINA\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\__init__.py", line 55, in <module>
    from pandas.core.api import (
  File "C:\Users\VALENTINA\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\api.py", line 29, in <module>
    from pandas.core.groupby import Grouper, NamedAgg
  File "C:\Users\VALENTINA\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\groupby\__init__.py", line 1, in <module>
    from pandas.core.groupby.generic import DataFrameGroupBy, NamedAgg, SeriesGroupBy
  File "C:\Users\VALENTINA\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\groupby\generic.py", line 60, in <module>
    from pandas.core.frame import DataFrame
  File "C:\Users\VALENTINA\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\frame.py", line 124, in <module>
    from pandas.core.series import Series
  File "C:\Users\VALENTINA\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\series.py", line 4572, in <module>
    Series._add_series_or_dataframe_operations()
  File "C:\Users\VALENTINA\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\generic.py", line 10349, in _add_series_or_dataframe_operations
    from pandas.core.window import EWM, Expanding, Rolling, Window
  File "C:\Users\VALENTINA\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\window\__init__.py", line 1, in <module>
    from pandas.core.window.ewm import EWM  # noqa:F401
  File "C:\Users\VALENTINA\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\window\ewm.py", line 5, in <module>
    import pandas._libs.window.aggregations as window_aggregations
ImportError: DLL load failed while importing aggregations: The specified module could not be found.

当我在Visual Code和IDLE中运行我的脚本时,出现了这个错误消息。

如果有人能帮助我解决问题,我将不胜感激

谢谢


你没有使用虚拟环境或类似的工具吗?你能分享一些关于你的环境的信息吗? - AMC
我正在使用 Python 3.8 和 Visual Studio Code 作为文本编辑器。 - Valentina Caffera
你是在VS Code还是命令行中运行代码?有时,如果你安装了Python2,VS Code会默认使用另一个Python安装。 - Matthew Barlowe
@Valentina 请将问题标记为已解决。另外,最好使用Anaconda安装Python,因为它附带了大多数情况下所需的常用软件包。 - Rohan Bojja
5个回答

25

我面临同样的问题。我使用的是python 3.7.5。默认情况下,pip install pandas 命令会安装版本 1.0.3。所以我回退到版本 1.0.1。

pip uninstall pandas
pip install pandas==1.0.1

现在它已经正常工作了。你可以尝试一下。


谢谢,我也安装了一个旧版本,成功解决了问题。 - Valentina Caffera
我遇到了与以下情况相同的问题,这个解决方案对我非常有效:使用Python 3.8.2、Pyinstaller 3.6在Windows 7上创建的exe文件。程序应该在Windows 10上运行。使用pandas 1.0.3时,exe在Windows 7上可以工作,但在Windows 10上无法工作。谢谢! - Charalamm
同样的问题在pandas 1.0.4中也存在。 - Zheng Liu
我也遇到了同样的问题,在Windows 10上使用Python 3.8.3 64位和Pandas 1.0.5。安装1.0.1版本后问题得以解决,现在的问题是为什么会出现这种情况? - Francesco

8

你在发布这个解决方案时是否有安装Pandas 1.0.3版本? - Charalamm
我有pandas 1.0.3。 - watupzack

2

在导入pandas时,我收到了两个错误消息,一个是OP中的错误消息,另一个是:

AttributeError: module 'pandas' has no attribute 'plotting'

我重新安装了该软件包/库,以解决问题。
pip uninstall pandas
pip install pandas==1.0.1

正如之前另一位用户所指出的,我现在使用Python 3.8.2与pandas 1.0.1协同工作,没有任何问题。


2

只需卸载pandas并重新安装pandas到1.0.1版本

例如:
pip卸载pandas
pip安装pandas==1.0.1


0

我遇到了相同的错误(Python 3.9)。这是解决方法:

pip uninstall pandas
upgrade pip=21.3.1
pip install pandas

1
我猜应该是“升级”而不是“upgrape”吧? - camille

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接