Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to use matplotlib after installation "no module named 'matplotlib'" [duplicate]

I am brand new to Python and am following the tutorial at this link: https://code.visualstudio.com/docs/python/python-tutorial

I was able to execute

python -m pip install matplotlib

However, then when trying to run script:

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 20, 100)
plt.plot(x, np.sin(x))
plt.show()

I get:

PS C:\Code\Astros\Prism> & C:/Users/USER/AppData/Local/Programs/Python/Python38/python.exe c:/Code/Astros/Prism/Prism.py
Traceback (most recent call last):
  File "c:/Code/Astros/Prism/Prism.py", line 1, in <module>
    import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib'
PS C:\Code\Astros\Prism> 

Any guidance would be much appreciated.

like image 426
user8788429 Avatar asked May 05 '26 08:05

user8788429


1 Answers

Can you check where the matplotlib package has been installed through this command?

pip show matplotlib

And you are using the global Python on your computer:

C:/Users/USER/AppData/Local/Programs/Python/Python38/python.exe

It should be different.

You can switch to the python interpreter which you have installed the packages you want to import. Or install the packages in the interpreter you are using.

like image 167
Steven-MSFT Avatar answered May 06 '26 20:05

Steven-MSFT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!