'Why can I not run matplotlib on Python 3.10?

My Issue. I am trying to run matplotlib on python 3.10 on my MacOS, but I get the following error:

ModuleNotFoundError: No module named 'matplotlib'

However, when I try running

pip install matplotlib

then I get back

Requirement already satisfied: cycler>=0.10 in ./.local/lib/python3.9/site-packages (from matplotlib) (0.10.0)
Requirement already satisfied: numpy>=1.16 in ./mambaforge/lib/python3.9/site-packages (from matplotlib) (1.21.2)
Requirement already satisfied: kiwisolver>=1.0.1 in ./.local/lib/python3.9/site-packages (from matplotlib) (1.3.2)
Requirement already satisfied: pyparsing>=2.2.1 in ./.local/lib/python3.9/site-packages (from matplotlib) (2.4.7)
Requirement already satisfied: pillow>=6.2.0 in ./.local/lib/python3.9/site-packages (from matplotlib) (8.3.2)
Requirement already satisfied: python-dateutil>=2.7 in ./.local/lib/python3.9/site-packages (from matplotlib) (2.8.2)
Requirement already satisfied: six in ./mambaforge/lib/python3.9/site-packages (from cycler>=0.10->matplotlib) (1.16.0)

Also, in response to

python3 --version

terminal says

Python 3.9.6

Also, I am able to use matplotlib just fine if I compile my code using Python 2.7.16 on Sublime Text 3.

My Question. How can I get matplotlib to run on Python 3.10?

Since I am still new to Python (or to programming, for that matter), please let me know if I should provide additional information.

Note: I have already looked at this and this, but I couldn't fix the issue.



Solution 1:[1]

I have had the same issue. It wasn't only for MatPlotLib, but Pandas and NumPy.

From seeing what the terminal tried to do, it seems that 3rd party libraries are not "compatible" yet. I am using my older version of python now.

When trying to get the libs, it just scrolled through all the versions of matplotlib, and gave errors. It might take some time before this is resolved.

Solution 2:[2]

I recently experienced this problem after installing Python 3.10.

Use version Python 3.9. That worked for me, but I can't figure out how to install matplotlib on 3.9 via the command line, but I'm using PyCharm right now, so I got it to work on there.

proof of installation

If you figure out how to install it via the command line, let me know! I'm using two versions of Python. I would like to know how to do it as well. I'm sure I can find it eventually. I believe if you uninstall Python 3.10 and leave only 3.9, it will work.

Solution 3:[3]

I found a temporary (unstable) fix for anyone desperate to run matplotlib (and many other packages, e.g. numba, scikit-learn, scipy, etc.) on Python 3.10 for Windows 10, as described by Amit Thinks. Amit uses a source of unstable binaries curated by Christoph Gohlke at UC Irvine, so these are likely not malware infested.

Solution 4:[4]

I faced the same issue , while trying to install matplotlib for python 3.10 . i faced 2 issues

1)It said wheel module not installed (installed via running pip install wheel)

2)It said it required microsoft visual c++ 14.0+ (it was already present when checked in control panel(x64)) (after installing wheel module while running the code[pip install matplotlib] for 3rd time). asked me to download visual studio community 2019 and build tools.... Did so.

And now i was able install matplotlib in python 3.10 and runs fine (when cheking in control panel there was another visual c++ 14.0+ installed (x86) along with (x64),dont know why it works only when x86 version of visual c++ is installed.

Solution 5:[5]

I had same issues with matplotlib,pandas,numpay etc on python 3.10 on window 10. I install with windows binaries packages.

after download "matplotlib?3.4.3?cp310?cp310?win_amd64.whl" use this commond:

pip install matplotlib-3.4.3-cp310-cp310-win_amd64.whl

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Stati5tiker
Solution 3 Hello Worlds
Solution 4 Nishanth saravanamurali
Solution 5 ibrahim