Pip install Matplotlib error with virtualenv
Solution 1
Building Matplotlib requires libpng
(and freetype
, as well) which isn't a python library, so pip
doesn't handle installing it (or freetype
).
You'll need to install something along the lines of libpng-devel
and freetype-devel
(or whatever the equivalent is for your OS).
See the building requirements/instructions for matplotlib.
Solution 2
To generate graph in png format you need to Install following dependent packages
sudo apt-get install libpng-dev
sudo apt-get install libfreetype6-dev
Ubuntu https://apps.ubuntu.com/cat/applications/libpng12-0/ or using following command
sudo apt-get install libpng12-0
Solution 3
As I have struggled with this issue twice (even after fresh kubuntu 15.04 install) and installing freetype did not solve anything, I investigated further.
The solution:
From github issue:
This bug only occurs if pkg-config is not installed;
a simple
sudo apt-get install pkg-config
will shore up the include paths for now.
After this installation proceeds smoothly.
Solution 4
As a supplementary, on Amazon EC2, what I need to do is:
sudo yum install freetype-devel
sudo yum install libpng-devel
sudo pip install matplotlib
Solution 5
On OSX I was able to get matplotlib to install via:
pip install matplotlib==1.4.0
only after I ran:
brew install freetype
Related videos on Youtube
Darwin Tech
Updated on July 08, 2022Comments
-
Darwin Tech almost 2 years
I am trying to install matplotlib in a new virtualenv.
When I do:
pip install matplotlib
or
pip install http://sourceforge.net/projects/matplotlib/files/matplotlib/matplotlib-1.1.0/matplotlib-1.1.0.tar.gz
I get this error:
building 'matplotlib._png' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -fPIC - DPY_ARRAY_UNIQUE_SYMBOL=MPL_ARRAY_API -DPYCXX_ISO_CPP_LIB=1 -I/usr/local/include -I/usr/include -I. -I/home/sam/django-projects/datazone/local/lib/python2.7/site-packages/numpy/core/include -I. -I/usr/include/python2.7 -c src/_png.cpp -o build/temp.linux-x86_64-2.7/src/_png.o src/_png.cpp:10:20: fatal error: png.h: No such file or directory compilation terminated. error: command 'gcc' failed with exit status 1
Anyone have an idea what is going on?
Any help much appreciated.
-
LondonRob almost 9 yearsYou may also see
The following required packages can not be built: freetype, png
which is the same error in (I think) a newer version ofpip
.
-
-
Darwin Tech about 12 yearsThanks for the info! I finally got it working by installing the following dependencies in ubuntu:
libpng-dev
,libjpeg8-dev
,libfreetype6-dev
. -
william_grisaitis about 11 years
sudo apt-get build-dep python-matplotlib
also does the trick! -
Achal Dave about 10 yearsIt may work, but note that it wants to install quite a few packages (more than can fit in this comment box), but about 0.6 GB worth of packages.
-
Jon about 10 yearsOn my debian (wheezy/unstable) system it was failing even with
libfreetype6-dev
installed. It turned out that I also neededpkg-config
installed. -
Drew over 9 yearsI actually have libfreetype6-dev intalled on ubuntu 14.04. Matplotlib seems not to be picking it.
-
mirandes over 9 yearsAlso check the versions you have installed are the ones stated in the requirements. I already had png (libpng) and freetype installed and "yum" said that they were already at the latest version. However, the version was still lower than the requirements so I had to go to the package's website and install by hand. That fixed it for me.
-
Roman almost 9 yearsIt is recommended to install a package to a virtual environment, which makes
pip
so nice. Hencesudo pip install
negates most of the usefulness that pip brings to the table. -
Lily over 8 yearsSame here. pip install matplotlib gave me error:
IMPORTANT WARNING: pkg-config is not installed. matplotlib may not be able to find some of its dependencies.
Freetype shows not installed. I just didbrew install pkg-config
and was able to get by. -
jpcgt almost 8 yearsI needed
sudo apt-get install pkg-config
first though. -
Jens de Bruijn almost 8 yearsThis is also the problem on Bash on Ubuntu on Windows Insider Preview
-
Ilmari Karonen over 6 years@RahulChauhan: Please post your alternative solution as a separate answer instead of trying to edit it into someone else's answer.