如何修复在python3上导入模块的错误

时间:2019-06-18 17:23:10

标签: python-3.x python-module

我在python上成功导入了模块,但仍然出现相同的输出错误ModuleNotFoundError: No module named ''错误。

我在mac终端中多次安装了matplotlib,eyeD3和mutagen:

#I used this code to install matplotlib on mac terminal
pip install --user  matplotlib

#I used this code to install eyeD3 on mac terminal
pip install eyeD3

当我尝试像下面的代码(或eyeD3)那样导入matplotlib时,出现了Traceback错误。

#to import matplotlib for example
import matplotlib.pyplot as plt 
x = [1,2,3]
y = [2,4,1] 
plt.plot(x, y) 
plt.xlabel('x - axis') 
plt.ylabel('y - axis') 
plt.title('My first graph!') 

plt.show() 

上面列出的所有模块均已正确安装,但是当我导入其中一个模块时,出现相同的常见错误ModuleNotFoundError: No module named ''

1 个答案:

答案 0 :(得分:0)

我认为您的计算机上至少有2个版本的python。 当您编写testhost.dll.config时,它将在python上安装matplotlib。 但是,当您启动程序时,将启动另一个版本的python。

要解决此问题: 命令pip install matplotlib将在所需版本上安装matplotlib。 如果要使用python 3.X,只需编写python -m pip install matplotlib 如果要使用计算机上安装的最新版本,请输入python3 -m pip install matplotlib。 您可以为每个必须安装的模块执行此操作。

希望它能对您有所帮助。

相关问题