Movatterモバイル変換


[0]ホーム

URL:


You are reading an old version of the documentation (v2.0.0). For the latest version seehttps://matplotlib.org/stable/faq/installing_faq.html
matplotlib

Navigation


Travis-CI:

Table Of Contents

Related Topics

This Page

Quick search

Installation

Report a compilation problem

SeeGetting help.

matplotlib compiled fine, but nothing shows up when I use it

The first thing to try is aclean install and see ifthat helps. If not, the best way to test your install is by running a script,rather than working interactively from a python shell or an integrateddevelopment environment such asIDLE which add additionalcomplexities. Open up a UNIX shell or a DOS command prompt and cd into adirectory containing a minimal example in a file. Something likesimple_plot.py for example:

importmatplotlib.pyplotaspltfig,ax=plt.subplots()ax.plot([1,2,3])plt.show()

and run it with:

pythonsimple_plot.py--verbose-helpful

This will give you additional information about which backends matplotlib isloading, version information, and more. At this point you might want to makesure you understand matplotlib’sconfigurationprocess, governed by thematplotlibrc configuration file which containsinstructions within and the concept of the matplotlib backend.

If you are still having trouble, seeGetting help.

How to completely remove matplotlib

Occasionally, problems with matplotlib can be solved with a cleaninstallation of the package.

The process for removing an installation of matplotlib depends on howmatplotlib was originally installed on your system. Follow the stepsbelow that goes with your original installation method to cleanlyremove matplotlib from your system.

Source install

Unfortunately:

pythonsetup.pyclean

does not properly clean the build directory, and does nothing to theinstall directory. To cleanly rebuild:

  1. Delete the caches from your.matplotlib configuration directory.
  2. Delete thebuild directory in the source tree.
  3. Delete any matplotlib directories or eggs from yourinstallationdirectory.

How to Install

Source install from git

Clone the main source using one of:

gitclonegit@github.com:matplotlib/matplotlib.git

or:

gitclonegit://github.com/matplotlib/matplotlib.git

and build and install as usual with:

>cdmatplotlib>pythonsetup.pyinstall

Note

If you are on debian/ubuntu, you can get all the dependenciesrequired to build matplotlib with:

sudoapt-getbuild-deppython-matplotlib

If you are on Fedora/RedHat, you can get all the dependenciesrequired to build matplotlib by first installingyum-builddepand then running:

su-c"yum-builddep python-matplotlib"

This does not build matplotlib, but it does get all of thebuild dependencies, which will make building from source easier.

If you want to be able to follow the development branch as it changesjust replace the last step with (make sure you havesetuptoolsinstalled):

>pythonsetup.pydevelop

This creates links in the right places and installs the commandline script to the appropriate places.

Note

Mac OSX users please see theBuilding on OSX guide.

Windows users please see theBuilding on Windows guide.

Then, if you want to update your matplotlib at any time, just do:

>gitpull

When you rungitpull, if the output shows that only Python files have beenupdated, you are all set. If C files have changed, you need to run thepythonsetup.pydevelop command again to compile them.

There is more information onusing git inthe developer docs.

Linux Notes

Because most Linux distributions use some sort of package manager,we do not provide a pre-built binary for the Linux platform.Instead, we recommend that you use the “Add Software” method foryour system to install matplotlib. This will guarantee that everythingthat is needed for matplotlib will be installed as well.

If, for some reason, you can not use the package manager, Linux usuallycomes with at least a basic build system. Follow theinstructions found above for how to build and install matplotlib.

OS-X Notes

Which python for OS X?

Apple ships OS X with its own Python, in/usr/bin/python, and its own copyof matplotlib. Unfortunately, the way Apple currently installs its own copiesof numpy, scipy and matplotlib means that these packages are difficult toupgrade (seesystem python packages). For that reason we strongly suggestthat you install a fresh version of Python and use that as the basis forinstalling libraries such as numpy and matplotlib. One convenient way toinstall matplotlib with other useful Python software is to use one of theexcellent Python scientific software collections that are now available:

These collections include Python itself and a wide range of libraries; if youneed a library that is not available from the collection, you can install ityourself using standard methods such aspip. Continuum and Enthought offertheir own installation support for these collections; see the Ananconda andCanopy web pages for more information.

Other options for a fresh Python install are the standard installer frompython.org, or installingPython using a general OSX package management system such ashomebrew ormacports. Power users onOSX will likely want one of homebrew or macports on their system to installopen source software packages, but it is perfectly possible to use thesesystems with another source for your Python binary, such as Anaconda, Canopyor Python.org Python.

Installing OSX binary wheels

If you are using recent Python fromhttps://www.python.org, Macports orHomebrew, then you can use the standard pip installer to install matplotlibbinaries in the form of wheels.

Python.org Python

Install pip following thestandard pip install instructions. For the impatient,open a new Terminal.app window and:

curl-Ohttps://bootstrap.pypa.io/get-pip.py

Then (Python 2.7):

pythonget-pip.py

or (Python 3):

python3get-pip.py

You can now install matplotlib and all its dependencies with:

pipinstallmatplotlib

Macports

For Python 2.7:

sudoportinstallpy27-pipsudopip-2.7installmatplotlib

For Python 3.4:

sudoportinstallpy34-pipsudopip-3.4installmatplotlib

Homebrew

For Python 2.7:

pip2installmatplotlib

For Python 3.4:

pip3installmatplotlib

You might also want to install IPython; we recommend you install IPython withthe IPython notebook option, like this:

  • Python.org Python:pipinstallipython[notebook]
  • Macportssudopip-2.7installipython[notebook] orsudopip-3.4installipython[notebook]
  • Homebrewpip2installipython[notebook] orpip3installipython[notebook]

Pip problems

If you get errors with pip trying to run a compiler likegcc orclang,then the first thing to try is toinstall xcode andretry the install. If that does not work, then checkGetting help.

Installing via OSX mpkg installer package

matplotlib also has a disk image (.dmg) installer, which contains atypical Installer.app package to install matplotlib. You should use binarywheels instead of the disk image installer if you can, because:

  • wheels work with Python.org Python, homebrew and macports, the disk imageinstaller only works with Python.org Python.
  • The disk image installer doesn’t check for recent versions of packages thatmatplotlib depends on, and unconditionally installs the versions ofdependencies contained in the disk image installer. This can overwritepackages that you have already installed, which might cause problems forother packages, if you have a pre-existing Python.org setup on yourcomputer.

If you still want to use the disk image installer, read on.

Note

Before installing via the disk image installer, be sure that all of thepackages were compiled for the same version of python. Often, the downloadsite for NumPy and matplotlib will display a supposed ‘current’ version ofthe package, but you may need to choose a different package from the fulllist that was built for your combination of python and OSX.

The disk image installer will have a.dmg extension, and will have a namelikematplotlib-1.4.0-py2.7-macosx10.6.dmg.The name of the installer depends on the versions of python and matplotlib itwas built for, and the version of OSX that the matching Python.org installerwas built for. For example, if the mathing Python.org Python installer wasbuilt for OSX 10.6 or greater, the dmg file will end in-macosx10.6.dmg.You need to download this disk image file, open the disk image file by doubleclicking, and find the new matplotlib disk image icon on your desktop. Doubleclick on that icon to show the contents of the image. Then double-click onthe.mpkg icon, which will have a name likematplotlib-1.4.0-py2.7-macosx10.6.mpkg, it will run the Installer.app,prompt you for a password if you need system-wide installation privileges, andinstall to a directory like/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages(exact path depends on your Python version).

Checking your installation

The new version of matplotlib should now be on your Python “path”. Check thiswith one of these commands at the Terminal.app command line:

python2.7-c'import matplotlib; print matplotlib.__version__, matplotlib.__file__'

(Python 2.7) or:

python3.4-c'import matplotlib; print(matplotlib.__version__, matplotlib.__file__)'

(Python 3.4). You should see something like this:

1.4.0/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/__init__.pyc

where1.4.0 is the matplotlib version you just installed, and the pathfollowing depends on whether you are using Python.org Python, Homebrew orMacports. If you see another version, or you get an error like this:

Traceback(mostrecentcalllast):File"<string>",line1,in<module>ImportError:Nomodulenamedmatplotlib

then check that the Python binary is the one you expected by doing one ofthese commands in Terminal.app:

whichpython2.7

or:

whichpython3.4

If you get the result/usr/bin/python2.7, then you are getting the Pythoninstalled with OSX, which is probably not what you want. Try closing andrestarting Terminal.app before running the check again. If that doesn’t fixthe problem, depending on which Python you wanted to use, considerreinstalling Python.org Python, or check your homebrew or macports setup.Remember that the disk image installer only works for Python.org Python, andwill not get picked up by other Pythons. If all these fail, please let usknow: seeGetting help.

Windows Notes

SeeWindows.

© Copyright 2002 - 2012 John Hunter, Darren Dale, Eric Firing, Michael Droettboom and the Matplotlib development team; 2012 - 2016 The Matplotlib development team. Last updated on Feb 20, 2017. Created usingSphinx 1.5.2.

[8]ページ先頭

©2009-2025 Movatter.jp