How to install matplotlib
Asked Answered
D

6

40

I installed python3.2 in ubuntu (the default edition is not deleted), and I follow the steps in here

However when i use

python3.2 setup.py install

I got:

 "error: command 'gcc' failed with exit status 1",
"src/ft2font.cpp:2224:29: error: ‘Int’ is not a member of ‘Py’"

And when I use sudo apt-get install python-matplotlib I can use matplot in python2.x, while I still can not use it with python3.2 How can I install matplot in python3.2 ?

Disapprobation answered 22/12, 2011 at 15:13 Comment(1)
As of version 1.2 ( released in November 2012 ) matplotlib does now support Python 3.2, but prior to this you would have needed to build from github as answered below.Plataea
T
51

Matplotlib supports python 3.x as of version 1.2, released in January, 2013.

To install it, have a look at the installation instructions. In general, call pip install matplotlib or use your preferred mechanism (conda, homebrew, windows installer, system package manager, etc). In some cases you may need to install additional non-python dependencies (libpng and freetype) through your system's package manager.

The answer below is left for historical reasons and as an example of installing the development version from github.


The current release of matplotlib doesn't support python3.

There's a github branch for python3 support for a couple of years now, but it hasn't been stable on anything other than linux until fairly recently. I believe that branch was recently merged back into the main branch.

If you want to use matplotlib on python3, you'll need to build from the current tip https://github.com/matplotlib/matplotlib

To build it, do something similar to the following:

git clone https://github.com/matplotlib/matplotlib
cd matplotlib
python3 setup.py build
sudo python3 setup.py install

If you don't have git installed, then you can just download a tarball of the current git tip instead: https://github.com/matplotlib/matplotlib/tarball/master

You'll need to have numpy installed for python3. (Installing it for python2 doesn't install it for python3.)

In most cases, that's all you'll need to do. For a default install, the only non-included python library is numpy. The other dependencies (e.g. libpng, freetype) are system libraries and if you can build matplotlib for python2, you already have them.

If you want a non-default install (e.g. if you want any of the non-default backends), then you'll need to copy the setup.cfg.default template to setup.cfg and edit it to match what you want. You'll probably only need to do this if you're planning to embed matplotlib in a gtk or qt application that you're writing, in which case you'll want the gtkagg or qtagg backends instead of just the default tkagg backend.

Terrorstricken answered 22/12, 2011 at 15:29 Comment(5)
How to build it? Can I just type 'python3.2 setup.py install'Disapprobation
Thank you. It really work. After that, I got "module' object has no attribute 'HTTPSHandler'", while it can be solved by linkDisapprobation
This is outdated, right? Ubuntu has a python3-matplotlib in latest releasesAntares
@Antares - Yes, absolutely! Matplotlib has supported python3 since version 1.2. At the time of the original question, though, it didn't yet. (I should update the answer, though. Thanks for the reminder!)Terrorstricken
I had to install using pip3 instead of regular pip because all of my other libraries were installed using pip3Compression
S
23

just to bump @endolith's comment up to answer level, from at least uBuntu 14-04 linux onwards, matplotlib support for python3 is built-in with apt:

sudo apt-get install python3-matplotlib

should install matplotlib for python3 with the necessary dependencies.

Sage answered 24/11, 2015 at 9:42 Comment(0)
U
5
sudo apt-get build-dep python-matplotlib

This should get all the dependencies required for installing matplotlib

Unsought answered 22/12, 2011 at 15:26 Comment(1)
It just install the libraries need to install matplotlib. After that you need to install with pip or with python3 setup.py install...Strangeness
F
3

Try Unofficial Windows Binaries for Python Extension Packages if you are running windows. http://www.lfd.uci.edu/~gohlke/pythonlibs/

Franchot answered 19/10, 2012 at 16:17 Comment(0)
S
0

I have followed the steps by Joe Kington on Ubuntu 14.04. Though those steps got me get started ran into few issues. I had to do the following additional steps. Hope it helps someone else who has similar problems.

  1. Install freetype package using

        sudo apt-get install libfreetype6-dev
    
  2. I had to install g++ because of this error: error trying to exec 'cc1plus': execvp: No such file or directory

        sudo apt-get install g++
    
  3. Then I have to install python3.4-dev because of : fatal error: Python.h: No such file or directory

        sudo apt-get install python3.4-dev
    

Now run the steps from Joe Kington. This worked for me.

Sathrum answered 6/5, 2015 at 0:42 Comment(0)
M
0

It's simplicity itself.

sudo pip install matplotlib will do the trick.

Meanie answered 20/11, 2016 at 12:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.