Reputation: 79
I'm trying to use matplotlib in python, specifically, in PyCharm IDE. I have Windows 10 and Python 3.8 and I checked that everything was up to date (like pip).
I installed matplotlib via pip with the command "pip install matplotlib", till then everything was okay because I didn't get any error in the cmd and it was successful.
The problem appears when I try to install the package into the project in PyCharm, and an error appears. I haven't found this error on any website and I've tried lots of things, like reinstalling python and PyCharm, installing the library with conda environment, also trying to install updated FreeType but I don't know how to do it...
Also, I noticed that when I import matplotlib in python.exe any error appears, so I thought the error might be in PyCharm, but this is just a speculation. Here's the error:
src/checkdep_freetype2.c(5): fatal error C1189: #error: "FreeType version 2.3 or higher is required. You may set the MPLLOCALFREETYPE environment variable to 1 to let Matplotlib download it."
I don't know how to install an updated FreeType version or setting the MPLLOCALFREETYPE to 1 as the error suggested.
If I can provide more information or more code please let me know, I don't know if I asked "correctly".
Update:
I've tried to write the command also in the terminal of venv and I think I get the same error, but with more detail, it mentions something regarding Microsoft visual studio. Here the error:
IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18
362.0\cppwinrt" /Tcsrc/checkdep_freetype2.c /Fobuild\temp.win32-3.8\Release\src/checkdep_freetype2.obj
checkdep_freetype2.c
src/checkdep_freetype2.c(5): fatal error C1189: #error: "FreeType version 2.3 or higher is required. You may set the MPLLOCALFREETYPE environment variable to 1 to let Matplotlib download
it."
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.25.28610\\bin\\HostX86\\x86\\cl.exe' failed with exit status 2
----------------------------------------
Command "C:\Users\Samuel\PycharmProjects\untitled\venv\Scripts\python.exe -u -c "import setuptools, tokenize;__file__='C:\\temp\\pip-install-pzdo9qwp\\matplotlib\\setup.py';f=getattr(tokenize,
'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\temp\pip-record-059s14h2\install-record.txt --single-version-e
xternally-managed --compile --install-headers C:\Users\Samuel\PycharmProjects\untitled\venv\include\site\python3.8\matplotlib" failed with error code 1 in C:\temp\pip-install-pzdo9qwp\matplotl
ib\```
Upvotes: 6
Views: 12507
Reputation: 1
In my case I uninstalled pycharm and reinstalled it and upgraded to tha last version. I tried all solutions mentioned above none of them solved problem completley. Problem solved and I run my code.
Upvotes: 0
Reputation: 121
I opened Pycharm as an Administrator so you can use commands and update everything easily. I also typed in terminal:
pip -m install matplotlib
to resolve dependencies and it worked. Also check on settings --> Project interpreter & update every package you can, it worked for me, btw I'm using python 3.8 and had no problems at all.
Upvotes: -1
Reputation: 41
Try updating your setuptools and pip to latest versions by clicking on the arrow up.
Because I also updated pip through command prompt and it was not working. Has to do something with the PATH it is looking in.
Works with latest version of PyCharm 2019.3.4 Professional and Python 3.8 on Windows 10.
Upvotes: 4
Reputation: 161
This happens to me occasionally. When PyCharm shows that it is installed in the interpreter but still gives an import error, I just create a new project and it imports error-free.
Upvotes: 0
Reputation: 339
Try:
sudo apt-get install libfreetype6-dev
sudo apt-get install pkg-config
sudo apt-get install libpng12-dev
sudo apt-get install pkg-config
Upvotes: 12
Reputation: 59
I got same problems like you and try to fix it with the error message but not work at all until I do one thing it fixes all problems, "Use python version 3.7"!!! don't use ver3.8 with PyCharm!
Upvotes: 1
Reputation: 79
I solved the problem just downloading another version of matplotlib.
python -m pip install -U matplotlib==3.2.0rc1```
Upvotes: 1
Reputation: 136
I'm assuming that you just went into the command prompt and typed "pip install matplotlib". This only installs matplotlib for the environment you installed, but pycharm creates its own environment.
So, to install matplotlib, go to the file explorer in pycharm and right click on "venv". Then click open in terminal. Once the terminal opens, you can use pip to install matplotlib, and then everything should work.
Upvotes: 0