Search code examples
python-3.xpython-module

How to fix errors importing modules on python3


I successfully import modules on python but I keep having the same output error ModuleNotFoundError: No module named '' error.

I installed matplotlib, eyeD3 and mutagen several times within the mac terminal:

#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

As I try to import matplotlib like the code below (or eyeD3) I get that Traceback error.

#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() 

All of the modules listed above installed correctly, but when I import one of the modules I get the same common error ModuleNotFoundError: No module named ''


Solution

  • I think you have at least 2 version of python on your computer. When you write pip install matplotlib, it install matplotlib on python. But when you start the programm, an other version of python is launch.

    To fix it : The command python -m pip install matplotlib will install matplotlib on the version that you want. If you want to use python 3.X, just write python3 -m pip install matplotlib If you want to use the last version that is install on your computer, write py -m pip install matplotlib. You can do that for every module that you have to install.

    I hope it will help you.