vscode在运行Import matplotlib.pyplot as plt时报错ImportError: DLL load failed: 找不到指定的模块

条件说明:已经安装matplotlib库和numpy库。

报错具体情况如图示:

网上找了一圈都没解决,最后问了一个同事大佬(ps俺只是小小实习生第一次接触python)

大佬甩了个链接放这:

matplotlib 的问题 - python 3.11:导入错误:导入时 DLL 加载失败 _path: - 堆栈溢出 (stackoverflow.com)

省流版步骤:

右键单击win图标

左键单击终端

 直接输入python -m pip install msvc-runtime

python -m pip install msvc-runtime

like this:

单机Enter

等待完成

再重启vscode。

我用以下代码测试了一下:(参考的(44条消息) matplotlib在vscode上使用_狂小虎的博客-CSDN博客_vscode matplotlib

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 20, 100)  # Create a list of evenly-spaced numbers over the range
plt.plot(x, np.sin(x))       # Plot the sine of each x point
plt.show()                   # Display the plot

单机运行键

最后运行结果是:

说明问题解决了。

 分析了一下原因:

可能是机器上python版本比较高,一些库什么的被移动了,

其他的没有深究。

以上仅供参考,未必都适用。

猜你喜欢

转载自blog.csdn.net/weixin_62884045/article/details/128938092