【DEBUG】解决pandas与numpy版本不协调导致的:Unable to import required dependencies: numpy: DLL load failed找不到指定的模块

一、问题表现

Traceback (most recent call last):
File “D:\hq_test.py”, line 74, in
from pytdx.hq import TdxHq_API
File “D:\Program\Anaconda3\lib\site-packages\pytdx\hq.py”, line 15, in
import pandas as pd
File “D:\Program\Anaconda3\lib\site-packages\pandas_init_.py”, line 17, in
“Unable to import required dependencies:\n” + “\n”.join(missing_dependencies)
ImportError: Unable to import required dependencies:
numpy: DLL load failed: 找不到指定的模块。

二、问题分析

安装和升级第三方库,有些第三方库依赖pandas及numpy,但其在安装升级过程中,可能导致pandas与numpy库版本不协调,从而导致pandas调用numpy时出现找不到numpy库模块的现象。

三、解决问题

1.参考解决方案

先查看当前安装的版本,然后卸载,再重新安装指定版本。通过这种适当降低pandas的版本号来解决兼容问题。有时候迫不得已,这种方法是可以临时解决问题的。

查看pandas可安装的所有版本号

随便传一个超大的版本号,即可获取所有可用版本号,如下:

pip install pandas==10000

cmd命令窗口反馈如下:
ERROR: Ignored the following versions that require a different python version: 1.4.0 Requires-Python >=3.8; 1.4.0rc0 Requires-Python >=3.8; 1.4.1 Requires-Python >=3.8; 1.4.2 Requires-Python >=3.8; 1.4.3 Requires-Python >=3.8
ERROR: Could not find a version that satisfies the requirement pandas10000(from versions: 0.1, 0.2, 0.3.0, 0.4.0, 0.4.1, 0.4.2, 0.4.3, 0.5.0, 0.6.0, 0.6.1, 0.7.0, 0.7.1, 0.7.2, 0.7.3, 0.8.0, 0.8.1, 0.9.0, 0.9.1, 0.10.0, 0.10.1, 0.11.0, 0.12.0, 0.13.0, 0.13.1, 0.14.0, 0.14.1, 0.15.0, 0.15.1, 0.15.2, 0.16.0, 0.16.1, 0.16.2, 0.17.0, 0.17.1, 0.18.0, 0.18.1, 0.19.0, 0.19.1, 0.19.2, 0.20.0, 0.20.1, 0.20.2, 0.20.3, 0.21.0, 0.21.1, 0.22.0, 0.23.0, 0.23.1, 0.23.2, 0.23.3, 0.23.4, 0.24.0, 0.24.1, 0.24.2, 0.25.0, 0.25.1, 0.25.2, 0.25.3, 1.0.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.0.5, 1.1.0, 1.1.1, 1.1.2, 1.1.3, 1.1.4, 1.1.5, 1.2.0, 1.2.1, 1.2.2, 1.2.3, 1.2.4, 1.2.5, 1.3.0, 1.3.1, 1.3.2, 1.3.3, 1.3.4, 1.3.5)
ERROR: No matching distribution found for pandas
10000

卸载后安装指定版本pandas库

pip uninstall pandas
pip install pandas==1.3.1

这个办法有时候还是不能解决问题。于是又进行了各种百度。最后通过如下办法解决。真是踏破铁鞋无觅处,得来全不费工夫。

2.推荐解决方案

今天来个终极解决办法,直接更新到最新版本。这个方法简单,高效,可以解决大部分问题。但有些软件因为不能使用高版本库,所以第一个方法还是有用的。

pip install --upgrade pandas -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install --upgrade numpy -i https://pypi.tuna.tsinghua.edu.cn/simple

升级后成功安装以下版本:
Successfully installed pandas-1.3.5
Successfully installed numpy-1.21.6

我的环境通过以下语句,执行完毕后,运行python代码正常了。

四、总结

以上两种办法,适用于各种库版本的问题。解决方法看似简单,可也是走过很多弯路才搞定的。在此,对消耗的脑细胞说声对不起啦!

以后发现库版本不兼容,找不到模块的问题,都先给升级到最新版本!
以后发现库版本不兼容,找不到模块的问题,都先给升级到最新版本!
以后发现库版本不兼容,找不到模块的问题,都先给升级到最新版本!

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
心中带点小风骚的头像心中带点小风骚普通用户
上一篇 2023年3月10日
下一篇 2023年3月10日

相关推荐