【问题标题】:What is causing Python to error when importing matplotlib?导入 matplotlib 时导致 Python 出错的原因是什么?
【发布时间】:2021-05-05 05:22:16
【问题描述】:

首先,我必须先说明 有一个错误正在显示,但正常的修复程序不起作用。 我的代码如下所示:

import matplotlib.pyplot as plt

x = [1,1,1]
y = [5,5,5]

plt.plot(x, y)

plt.xlabel('- Hours Spent Studying -')
plt.ylabel('- Test Scores (in %) -')

plt.title('- Science Scores -')
plt.show()

根据我对 matplotlib 的了解,这应该绘制给定点。我发现的错误是:

import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib'

我立即假设我没有正确安装matplotlib或安装在正确的目录中,所以我尝试进入安装python39的目录,并尝试pip install matplotlib,它告诉我已经在目录中安装了matplotlib。迷茫中,我回到自己的代码目录,再次运行,同样的错误又出现了。 有没有人对为什么会发生这种情况有任何建议或修复?我的操作系统是Win10。

【问题讨论】:

    标签: python python-3.x matplotlib


    【解决方案1】:

    尝试通过python3.9 code.py运行

    【讨论】:

    • 谢谢!我刚刚做了“python3.9(我的文件名)”并且它有效!非常感谢!
    猜你喜欢
    • 2011-09-29
    • 2012-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多