Pick a Python interpreter in VSCode, activate its virtual environment in the integrated terminal, then run python -m pip install matplotlib. That’s the whole install.
Where people get stuck is the environment. The package goes into whatever environment that interpreter belongs to, and the editor itself never holds it. Run the right command in the wrong environment and you still get ModuleNotFoundError.
Matplotlib is the plotting library most Python people reach for first, in plain scripts and in Jupyter notebooks alike.
The current release, Matplotlib 3.11.2 (PyPI, published September 11, 2026), requires Python 3.11 or newer. So the interpreter you choose matters before anything else does.
What do you need before installing Matplotlib in VSCode?
You need VSCode and the Python extension from the Visual Studio Marketplace. You also need an actual Python interpreter, installed on its own, because VSCode doesn’t ship one.
The extension is the bridge. It lets the editor talk to Python, while the interpreter is the thing that runs your code. Matplotlib lives in that interpreter’s environment.
Installed Python while VSCode was open? Close and reopen the terminal (or restart VSCode) so it picks up the new interpreter.
Which Python version does Matplotlib support?
Anything from Python 3.11 up works with the current release.
- Matplotlib 3.11.2 is the latest release, published September 11, 2026 (PyPI)
- The package classifiers list Python 3.11, 3.12, 3.13 and 3.14
- Python 3.10 reached end of life on October 1, 2026 (Python Developer’s Guide)
- Python 3.11 now gets security fixes only, scheduled to end October 2027
That leaves less room than it looks. The oldest Python that can install today’s Matplotlib is already in security-only mode, so for a new project I’d go with 3.12 or 3.13 and not think about it again for a while.
How do you check Python and pip in the terminal?
Open the integrated terminal from the Terminal menu. Run python --version first.
Then check pip with python -m pip --version. The output also shows which Python that pip belongs to, which comes in handy later.
On Windows, pip’s own guide uses py -m pip, because the py launcher picks the latest Python interpreter you have installed.
If the terminal answers with “pip is not recognized”, that’s a separate problem with its own fix, covered in this walkthrough for the pip error in VSCode.
Which install method should you use: pip, conda or uv?
Whichever tool built the environment VSCode is pointing at. If your Python came from python.org, that’s pip inside a venv. Anaconda or Miniconda means conda. A project already set up with uv stays with uv.
Mixing managers is the usual way packages land somewhere you didn’t expect. If you’re still deciding between tools, a side-by-side of venv, conda and poetry shows where each one fits.
| Method | Command | Best for | Catch |
|---|---|---|---|
| pip in a venv | python -m pip install matplotlib | Plain Python from python.org | Wrong interpreter if not selected |
| conda | conda install -c conda-forge matplotlib | Anaconda and Miniconda users | Environment must be active |
| uv | uv add matplotlib | Projects already managed with uv | Needs uv 0.8.7 or newer for tkagg |
All of these commands come straight from Matplotlib’s install page.
pip in a venv

A new venv bootstraps pip through ensurepip unless you pass –without-pip, so there’s nothing extra to install.
This is my default. It comes with Python, every project gets its own isolated environment, and the commands are the same on Windows, macOS and Linux.
The downside is that it’s all manual. You create the environment, you select it in VSCode, and you’re on your own for managing Python versions.
conda
Matplotlib is available from the Anaconda main channel and from conda-forge. It also ships inside the Anaconda distribution, so if that’s what you have, run the import check before installing anything. It may already be there.
Conda makes sense when your data work already lives in conda environments. Just make sure the VSCode terminal has the right one active, or the install goes to a different environment than the one VSCode runs your code with.
uv
Matplotlib’s docs warn that the tkagg backend needs uv 0.8.7 or newer and up-to-date uv-managed Python builds. Older ones can leave it broken.
To fix that, run uv self update and uv python upgrade --reinstall. Or install a different GUI framework with uv add matplotlib pyside6.
There’s a VSCode detail here that catches people. As of November 2026, the Python Environments extension sets alwaysUseUv to true by default, so when uv is available the extension uses it for venv creation and package installation. You might be using uv without having chosen it.
So check which manager actually built your environment before picking a command. uv add records Matplotlib in the project’s pyproject.toml and syncs the project’s .venv, creating it if it doesn’t exist yet.
How to create a virtual environment and select its interpreter
You make a .venv folder in the project and then tell VSCode to use the interpreter inside it. The Command Palette and the Status Bar both handle this.
Creating the environment
Running Python: Create Environment from the Command Palette walks you through it. You pick venv or conda, the Python version, a name, and optionally a dependency file to install from.
Quick Create is faster. The + button in the Environment Managers view uses your default manager (venv unless you changed it), builds an environment named .venv with the latest Python available, and installs from requirements.txt or pyproject.toml if either exists.
Or skip the UI and type python -m venv .venv in the terminal. It creates the environment in the current folder. When I do it this way I add --upgrade-deps, which upgrades pip to the latest version on PyPI.
One thing to avoid: copying or moving the folder later. The Python docs say venvs are “not considered as movable or copyable”, because scripts inside hold absolute paths to the interpreter. If the project moves, recreate the environment at the new location and reinstall from a requirements file.
Selecting the interpreter
Click the Python version in the Status Bar, or run Python: Select Interpreter. There’s a separate guide on changing the Python interpreter in VSCode if you want more detail.
If you haven’t picked anything, the extension goes for workspace-local environments (.venv, venv) first, then global or system interpreters.
Explicit settings override that auto-selection, in this order:
- pythonProjects[]
- defaultEnvManager, only if you set it
- The legacy python.defaultInterpreterPath
By default the extension searches the workspace with the glob ./**/.venv. Environment not in the list? Run Python Environments: Refresh All Environment Managers to rescan.
Now confirm it worked. Open a new terminal and the environment name should appear at the start of the prompt.
No prefix means you’ll need to activate it by hand. This guide to activating a venv in VSCode walks through it.
I also like to run python -c "import sys; print(sys.executable)" as a sanity check. The path should end inside your .venv folder.
Installing Matplotlib with pip in the VSCode terminal
With the environment active, run python -m pip install matplotlib. Matplotlib and its dependencies go into whichever environment that python belongs to.
That’s the reason to type python -m pip and not just pip. It runs pip with the interpreter you specify as python, so there’s no guessing which pip you got.
- Open a terminal in VSCode (Terminal menu, New Terminal).
- Activate the environment, using the command for your shell below.
- Update pip:
python -m pip install -U pip - Install the package:
python -m pip install matplotlib - Confirm the install:
python -m pip show matplotlib
Matplotlib’s install page runs python -m pip install -U pip right before installing the package, in the same command block.
| Platform | Shell | Activation command |
|---|---|---|
| macOS, Linux | bash, zsh | source .venv/bin/activate |
| Windows | cmd.exe | .venv\Scripts\activate.bat |
| Windows | PowerShell | .venv\Scripts\Activate.ps1 |
These come from the Python venv documentation. PowerShell may refuse to run the script until you run Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser, which is annoying the first time and then you forget it ever happened.
Outside an environment, Windows users run py -m pip install matplotlib instead. If your Mac or Linux system only provides python3, use that.
What pip installs along with Matplotlib
Matplotlib needs 9 runtime packages, and pip grabs them for you: contourpy, cycler, fontTools, kiwisolver, NumPy, packaging, Pillow, pyparsing and python-dateutil.
If you pin versions by hand, the minimums worth knowing are NumPy 1.25 or newer, Pillow 9.0 or newer, and fontTools 4.28.2 or newer. Those come from the dependencies page of the Matplotlib 3.11.2 documentation.
When pip compiles from source instead of downloading a wheel
Pip normally downloads a prebuilt wheel. When none matches your operating system and Python version, it tries to build Matplotlib from source, and that build can fail.
The documented fix is the --prefer-binary flag. It selects the newest Matplotlib version that has a precompiled wheel for your OS and Python. Run python -m pip install -U matplotlib --prefer-binary.
On Linux, an old pip causes the same thing because it doesn’t recognize newer wheel tags. Matplotlib 3.11.2’s x86-64 wheels for Python 3.11 to 3.13 are tagged manylinux2014, which pip understands from 19.3. Its aarch64 wheels and its Python 3.14 wheels use manylinux_2_28 tags, though, and pip only recognizes those from 20.3. Yet another reason to upgrade pip before anything else.
How to confirm Matplotlib installed correctly
If you can import it, read its version, and get a plot window from a script in VSCode, you’re done.
Checking the version and install path
Matplotlib’s install page checks the version by importing the package and printing its __version__ attribute. I add the file path to the same line:
python -c "import matplotlib; print(matplotlib.__version__, matplotlib.__file__)"
The __file__ value is the folder Matplotlib loaded from. It should sit inside your .venv folder.
Somewhere else? Then VSCode and pip disagree about which environment is active.
Running a test plot
Save this as test_plot.py in the project folder.
import matplotlib
import matplotlib.pyplot as plt
print(matplotlib.get_backend())
plt.plot((1, 4, 6))
plt.show()This is the smoke test from Matplotlib’s own backends documentation. Run it with the editor’s Run button, or see this guide to running Python in VSCode for other ways.
You should see a backend name printed in the terminal and a window with a line through three points.
Why plt.show() sometimes opens nothing
A silent plt.show() usually means a non-interactive backend. Agg can only write to files, and Matplotlib falls back to it on Linux when it cannot connect to an X or Wayland display.
Without a backend set, Matplotlib takes the first usable one from this list: MacOSX, QtAgg, GTK4Agg, Gtk3Agg, TkAgg, WxAgg, Agg. TkAgg requires Tkinter.
The quick workaround is saving the figure with matplotlib.pyplot.savefig('filename'), which is the documented route for non-interactive backends. The better fix is choosing a backend yourself.
Matplotlib reads backend settings from these places, and the last one on the list wins:
- The backend parameter in matplotlibrc
- The MPLBACKEND environment variable
- A call to matplotlib.use(), made before any figure exists
Matplotlib’s docs discourage setting MPLBACKEND globally, for example in .bashrc, because it overrides every matplotlibrc, even one in the current working directory.
Installing Matplotlib for Jupyter notebooks in VSCode
Look at the kernel picker in the top right of the notebook. Whatever it shows is what runs your cells, and that kernel’s environment is where Matplotlib has to be installed.
You’ll need the Jupyter extension (ms-toolsai.jupyter), which gives VSCode native notebook support, plus a Python environment with ipykernel in it. Want to debug cells? Then ipykernel has to be version 6 or newer.
Posit’s VSCode guide adds ipykernel to the virtual environment with python -m pip install ipykernel.
- Run Notebook: Select Notebook Kernel from the Command Palette, or use the picker, and choose the .venv kernel.
- In a new cell, run
%pip install matplotlib. The magic runs pip within the current kernel. - In the next cell, run
import matplotliband print its version. - If the import fails, restart the kernel from the notebook editor toolbar.
About that restart. The IPython docs don’t say whether you need one after installing packages, and the VSCode notebook page doesn’t either.
My rule is to restart only when the import still fails. You lose the cell state, nothing more.
Installing from the terminal only helps the notebook if the terminal’s environment happens to be the kernel’s environment. That’s easy to get wrong, which is why I stick with %pip inside notebooks.
Why does VSCode still say “No module named matplotlib” after installing?
Almost always, pip put Matplotlib into one Python and VSCode is running a different one. Compare the path from python -m pip --version with the one from python -c "import sys; print(sys.executable)".
Different environments in those two paths means you’ve found it. Select the right interpreter and install again.
| Symptom | Cause | Fix |
|---|---|---|
| ModuleNotFoundError at runtime | pip targeted a different interpreter | Select the .venv interpreter, reinstall |
| Squiggle on the import, script runs | Pylance sees another environment | Select the environment, install there |
| externally-managed-environment error | System Python is marked as managed | Install inside a venv |
| Works in terminal, fails in notebook | Kernel differs from terminal environment | Pick the .venv kernel or use %pip |
Pylance warning versus a runtime error
These get confused a lot. Pylance’s reportMissingImports warns when an import cannot be resolved because the module is missing or not installed.
That’s static analysis. The squiggle tells you what Pylance can resolve, not what happens when the script runs. If the script runs fine and the squiggle stays, Pylance and your terminal are probably looking at different environments (my inference, not a line from the docs).
The Pylance docs suggest installing the package with pip or selecting the correct Python environment. They also mention python.analysis.extraPaths, but that’s for your own code sitting in a non-standard folder and has nothing to do with Matplotlib.
Restarting the language server isn’t mentioned on the Pylance page at all. So before you write off a lingering squiggle as stale, make sure the script actually runs.
The externally-managed-environment error
You’ll mostly see this on Debian and Ubuntu, and it stops the install before anything downloads. The distributor places an EXTERNALLY-MANAGED file in the interpreter’s stdlib directory, and that file is what triggers it.
The marker is opt-in, so an interpreter compiled upstream is not marked by default. That’s why python.org installs rarely show it.
The recommended fix is a virtual environment, with packages installed through that environment’s python and pip. The setup steps above already cover building one.
There’s a flag that bypasses the check, --break-system-packages, and I’d leave it alone. The spec says the option should carry a connotation that its use is risky, and it installs into a Python your operating system depends on. PEP 668, approved in June 2022, defines the whole mechanism.
If an environment gets truly tangled, deleting the venv and building a new one is usually faster than debugging it.
How do you keep the same Matplotlib version on every machine?
Freeze the environment that works into a requirements file, commit it, and install from it everywhere else. pip freeze prints installed packages in name==version format, sorted case-insensitively.
python -m pip freeze > requirements.txt
python -m pip install -r requirements.txtThe first line runs in the working environment, the second in the new one. The pip docs show exactly this freeze-then-install pattern for reproducing one environment in another.
It has a limit, though. pip freeze does not compute a lockfile or a solver result. You get a snapshot of what was installed that day, with no promise that a future resolve will match.
A couple of flags help. –exclude-editable drops editable packages from the output, and –all stops pip freeze from skipping bootstrap tools. On Python 3.12 and later, only pip is skipped by default anyway.
Whenever you upgrade Matplotlib on purpose, re-freeze and commit the file in the same change.
Matplotlib in VSCode FAQ
Do you need a virtual environment to install Matplotlib in VSCode?
No. pip will install into the global interpreter without one. A virtual environment just keeps Matplotlib’s dependencies away from your other projects, which is worth it.
uv is stricter and requires a virtual environment by default, unlike pip.
How do you upgrade Matplotlib to the latest version?
In the active environment, run python -m pip install -U matplotlib. Matplotlib’s install page also upgrades pip first with python -m pip install -U pip.
Print matplotlib.__version__ afterward to confirm the new release loaded.
Can you install a specific Matplotlib version?
Yes, with a double equals sign: python -m pip install matplotlib==3.11.2.
Pip’s guide uses the same name==version form, and it accepts a minimum version such as ‘SomePackage>=1.0.4’ too.
How do you uninstall Matplotlib?
Run python -m pip uninstall matplotlib in the active environment and confirm the prompt.
Only Matplotlib goes. Dependencies such as NumPy stay installed.
A Matplotlib Setup in VSCode That Lasts
Give each project its own venv and treat the selected interpreter as the one source of truth. Most of the problems in this article come from forgetting the second part.
When something breaks later, go in this order:
- Confirm the interpreter path
- Reinstall with
python -m pip - Adjust Pylance settings last
The first two actually change which environment holds the package. Pylance settings only change what the editor reports, so if you start there you can end up hiding the real problem.
You do pay for this in disk space, since every venv carries its own copy of Matplotlib and each dependency. I think that’s a fair price.
The advice holds while Matplotlib’s minimum Python version stays where PyPI lists it today (verified November 20, 2026). A release that raises it changes which interpreter new projects need.
Once your plots render, a good next step is learning to debug Python scripts in VSCode.
- How Software Teams Can Retire Old Hardware Without Losing Sleep - December 2, 2026
- PyCharm vs VS Code for Python: Speed, Debugging, Cost - December 1, 2026
- How to Choose a Digital Transformation Consulting Partner - November 30, 2026



