Python (Win 10): Installing matplotlib requires packages "freetype" and "png"?
Solution 1
Use a more powerful installer
I would recommend to use Anaconda or Miniconda. In my experience with many Windows users, this is the simplest way to install packages such as matplotlib.
Anaconda
Anaconda comes with many packages for scientists. Matplotlib works out of the box. Just install as user not root.
Minoconda
If you don't want all packages of Ananconda use Miniconda
Conda
Both ways of installation (Anaconda or Miniconda) provide conda
. It is an improved pip
/virtualenv
.
You can install matplotilb with this command:
conda install matplotlib
Enviroments:
You can create a new environment and install the packages you like:
conda create -n my_project35 python=3.5
activate my_project35
conda install matplotlib
or
conda create -n my_project27 python=2.7
activate my_project27
conda install matplotlib
Combine with pip
You can still use pip
. conda
"understands" what it is doing.
Solution 2
One snake is enough!
[This is for folks using the Linux Bash Shell on Windows 10.]
If you don't want to go the Anaconda route, you can install freetype (and png) by executing the following in the Windows 10 Bash shell:
sudo apt-get install freetype6-dev
The above command will also automatically install libpng. However, due to an error, the system will not 'realize' it has installed freetype, so you'll need to manually install pkg-config:
sudo apt-get install pkg-config
Thereafter you should be able to install matplotlib via pip without further incident.
sudo pip install matplotlib
Solution 3
I tired downloading matplotlib 2.2.2 with python 3.9.5, getting freetype & png errors for hours.
After downloading python 3.7.9 and removing python 3.9.5 from environment variables, installing matplotlib 2.2.2 worked with no problems!
user3639207
Updated on June 09, 2022Comments
-
user3639207 almost 2 years
I've been trying to install Python's matplotlib library for use with PyPlot, for use with Julia. I managed to get everything in place except for this one final library, and I feel as though I've hit a deadend trying to get it working.
When trying to install matplotlib (I've attempted using pip, regular python install, and easy_install), I get the following message at the very end of the install output, after which it is NOT installed:
* The following required packages can not be built: * freetype, png
Confused about this, I looked around online and installed both of these (at least, what I think these were). One was the freetype project, and the other was LibPng, which was the closest thing I could find to a "png package" for windows or python in general.
This didn't initially work (for either of them), and I read somewhere that I needed a freetype.dll in my system32 folder. It was a long shot, but I went to where I installed freetype and pulled out the dll and renamed it, placing it in system32. This of course did not work (again, long shot).
Anyway, that's where I'm at. No idea where to go from here, and I'm unsure if I even grabbed the correct "packages" I should be using. Thoughts?
Thanks in advance,
Ollie
-
user3639207 over 8 yearsYay, it worked! Although, whenever I use PyPlot through Julia, it screams out the warning "WARNING: redefining constant libpythondl" 20 times as it's computing things. Doesn't seem to stop it from working though. Thanks for your help!
-
user3639207 over 8 yearsScratch that last point, I deleted the Julia package folder and freshly installed Julia, fixed the issue straight up. Thanks for your help again!
-
Parth Bhoiwala over 7 years@Mike, this answer should get like 1000 upvotes. I researched for several hours and this was the easiest one to implement and it works like a charm. Thanks
-
sourabhxiii almost 7 yearsShould it be
libfreetype6-dev
? -
marisano almost 7 years@Sourabh, I installed freetype6-dev; I don't know if installing libfreetype6-dev would also work. Did you try it? I wonder if you would still need to run pkg-config going that route... If you do install libfreetype6-dev, you may need to manually install libpng.
-
DonPaulie over 2 yearsFirst I thought, that's not a solution. Then I tried downgrade from 3.8.12 to 3.7.9 and it works like a charm