0
votes

hi I installed matplotlib in vs code on Windows 10 when I installed matplotlib it worked but when I run a simple program I get this import tkinter as tk.py", line 2, in import matplotlib.pyplot as plt ModuleNotFoundError: No module named 'matplotlib'

2
First of all your question is not clear and requires editing. Please revise your question. But based on the error, matplotlib is missing. Have you installed matplotlib? use pip install matplotlibm.i.cosacak
@m.1.cosacak yes i have do i have to uninstall matplotlib and if so how im using visual studio codeLinuxuser1234

2 Answers

0
votes

I assume you already have Python interpreter in left/bottom of your VS as seen here and terminal opened in VS

If you donot have a working folder for your VS use the followings;

(1) create a folder wherever you want, let say on your desktop named as myVSworks

(2) from VS, File > Open Folder ..., then seleck Desktop by double-click and then select myVSworks folder and press Seleck Folder.

(3) in your VS terminal perform followings;

python -m venv myVSvenv

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process

myVSvenv\Scripts\activate

pip install matplotlib

(4) create a testme.py file and add the followings

import matplotlib as mplt
print(mplt.__version__)

(5) from terminal enter following python testme.py

if it print the version of matplotlib that means it works.

I think the main step here is to use: Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process See above

for details check here

0
votes

Please do some of the things mentioned below:

  1. Firstly go to extensions in vs code and uninstall and install the python extension (Microsoft) once then restart. Check if it works. If not then follow below.

  2. Please ensure you have selected the correct python interpreter that has matplotlib installed in it. At the moment you haven't selected it, the bottom left-hand corner of the status bar shows the version of Python you have selected. Please click on that label (status bar item)

    or use the command Python: Select Interpreter to change it to the right interpreter.

  3. Navigate to "C:\Users\username\AppData\Local\Programs\Python" and see how many versions of Python (folder such as Python38, etc.) are there.

  4. If there are multiple version folders then go inside every folder in "Lib\site-packages" and check for "matplotlib" folder.

  5. Select the same version in vscode where matplotlib was found (for eg. python 3.8.* if matplotlib was found inside Python38).

Tip: Use the 3.8 version of python currently as because it is more stable in external packages.