Python install matplotlib version

# Installing

If you wish to contribute to the project, it’s recommended you install the latest development version.

# Installing an official release

Matplotlib and its dependencies are available as wheel packages for macOS, Windows and Linux distributions:

python -m pip install -U pip python -m pip install -U matplotlib 

The following backends work out of the box: Agg, ps, pdf, svg and TkAgg.

For support of other GUI frameworks, LaTeX rendering, saving animations and a larger selection of file formats, you may need to install additional dependencies.

Although not required, we suggest also installing IPython for interactive use. To easily install a complete Scientific Python stack, see Scientific Python Distributions below.

# Test data

open in new window do not contain test data or example code.

If you want to try the many demos that come in the Matplotlib source distribution, download the *.tar.gz file and look in the examples subdirectory.

  • extract the lib/matplotlib/tests or lib/mpl_toolkits/tests directories from the source distribution;
  • install test dependencies: pytest

open in new window , Pillow, MiKTeX, GhostScript, ffmpeg, avconv, ImageMagick, and Inkscape

# Third-party distributions of Matplotlib

# Scientific Python Distributions

open in new window are excellent choices that «just work» out of the box for Windows, macOS and common Linux platforms. WinPython

open in new window is an option for Windows users. All of these distributions include Matplotlib and lots of other useful (data) science tools.

# Linux: using your package manager

If you are on Linux, you might prefer to use your package manager. Matplotlib is packaged for almost every major Linux distribution.

  • Debian / Ubuntu: sudo apt-get install python3-matplotlib
  • Fedora: sudo dnf install python3-matplotlib
  • Red Hat: sudo yum install python3-matplotlib
  • Arch: sudo pacman -S python-matplotlib

# Installing from source

If you are interested in contributing to Matplotlib development, running the latest source code, or just like to build everything yourself, it is not difficult to build Matplotlib from source. Grab the latest tar.gz release file from the PyPI files page

open in new window , or if you want to develop Matplotlib or just need the latest bugfixed version, grab the latest git version, and see Install from source

The standard environment variables CC , CXX , PKG_CONFIG are respected. This means you can set them if your toolchain is prefixed. This may be used for cross compiling.

export CC=x86_64-pc-linux-gnu-gcc export CXX=x86_64-pc-linux-gnu-g++ export PKG_CONFIG=x86_64-pc-linux-gnu-pkg-config 

Once you have satisfied the requirements detailed below (mainly Python, NumPy, libpng and FreeType), you can build Matplotlib.

cd matplotlib python -mpip install . 

open in new window file which you can use to customize the build process. For example, which default backend to use, whether some of the optional libraries that Matplotlib ships with are installed, and so on. This file will be particularly useful to those packaging Matplotlib.

If you have installed prerequisites to nonstandard places and need to inform Matplotlib where they are, edit setupext.py and add the base dirs to the basedir dictionary entry for your sys.platform ; e.g., if the header of some required library is in /some/path/include/someheader.h , put /some/path in the basedir list for your platform.

# Dependencies

Matplotlib requires the following dependencies:

Optionally, you can also install a number of packages to enable better user interface toolkits. See What is a backend?

open in new window for more details on the optional Matplotlib backends and the capabilities they provide.

For better support of animation output format and image file formats, LaTeX, etc., you can install the following:

Matplotlib depends on non-Python libraries.

open in new window can be used to find required non-Python libraries and thus make the install go more smoothly if the libraries and headers are not in the expected locations.

If not using pkg-config (in particular on Windows), you may need to set the include path (to the FreeType, libpng, and zlib headers) and link path (to the FreeType, libpng, and zlib libraries) explicitly, if they are not in standard locations. This can be done using standard environment variables — on Linux and OSX:

export CFLAGS='-I/directory/containing/ft2build.h . ' export LDFLAGS='-L/directory/containing/libfreetype.so . ' 
set CL=/IC:\directory\containing\ft2build.h . set LINK=/LIBPATH:C:\directory\containing\freetype.lib . 

where . means «also give, in the same format, the directories containing png.h and zlib.h for the include path, and for libpng.so / png.lib and libz.so / z.lib for the link path.»

The following libraries are shipped with Matplotlib:

  • Agg : the Anti-Grain Geometry C++ rendering engine;
  • qhull : to compute Delaunay triangulation;
  • ttconv : a TrueType font utility.

# Building on Linux

It is easiest to use your system package manager to install the dependencies.

If you are on Debian/Ubuntu, you can get all the dependencies required to build Matplotlib with:

sudo apt-get build-dep python-matplotlib 

If you are on Fedora, you can get all the dependencies required to build Matplotlib with:

sudo dnf builddep python-matplotlib 

If you are on RedHat, you can get all the dependencies required to build Matplotlib by first installing yum-builddep and then running:

su -c "yum-builddep python-matplotlib" 

These commands do not build Matplotlib, but instead get and install the build dependencies, which will make building from source easier.

# Building on macOS

The build situation on macOS is complicated by the various places one can get the libpng and FreeType requirements (MacPorts, Fink, /usr/X11R6), the different architectures (e.g., x86, ppc, universal), and the different macOS versions (e.g., 10.4 and 10.5). We recommend that you build the way we do for the macOS release: get the source from the tarball or the git repository and install the required dependencies through a third-party package manager. Two widely used package managers are Homebrew, and MacPorts. The following example illustrates how to install libpng and FreeType using brew :

brew install libpng freetype pkg-config 

If you are using MacPorts, execute the following instead:

port install libpng freetype pkgconfig 

After installing the above requirements, install Matplotlib from source by executing:

Note that your environment is somewhat important. Some conda users have found that, to run the tests, their PYTHONPATH must include /path/to/anaconda/. /site-packages and their DYLD_FALLBACK_LIBRARY_PATH must include /path/to/anaconda/lib.

# Building on Windows

open in new window for how to set up a build environment.

Since there is no canonical Windows package manager, the methods for building FreeType, zlib, and libpng from source code are documented as a build script at matplotlib-winbuild

There are a few possibilities to build Matplotlib on Windows:

# Wheel builds using conda packages

This is a wheel build, but we use conda packages to get all the requirements. The binary requirements (png, FreeType. ) are statically linked and therefore not needed during the wheel install.

Set up the conda environment. Note, if you want a qt backend, add pyqt to the list of conda packages.

conda create -n "matplotlib_build" python=3.7 numpy python-dateutil pyparsing tornado cycler tk libpng zlib freetype msinttypes conda activate matplotlib_build 

For building, call the script build_alllocal.cmd in the root folder of the repository:

Источник

How to install numpy and matplotlib in the right python version?

I’m trying to install numpy, matplotlib, and scipy in the right python version. Initially I was testing with different python versions (3.2, 2.7, 2.6). I removed all these versions using: How to uninstall Python 2.7 on a Mac OS X 10.6.4? Afterwards, I reinstalled Python 2.7.11. when I try to install numpy, matplotlib and scipy, using pip, I get the following message: Requirement already satisfied (use —upgrade to upgrade) . In my terminal, I tried the following:

$ which python /Library/Frameworks/Python.framework/Versions/2.7/bin/python $ python Python 2.7.11 (v2.7.11. ) . >>> import numpy ImportError: No module named numpy $ /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python Python 2.7.10 (default, . . >>> import numpy >>> numpy.__version__ '1.8.0rc1' 

for some reason these packages got installed in 2.7.10 and not 2.7.11, which is the version I downloaded from python.org. Also, I don’t even know how I got the 2.7.10 version. How can I fix this issue?

You should also add the exact statements you used to install numpy, and also check the path of the tool you used to install (e.g pip or setuptools) with which -a

$ which -a pip /usr/local/bin/pip The installation commands: ruby -e «$(curl -fsSkL raw.github.com/mxcl/homebrew/go)» export PATH=/usr/local/bin:/usr/local/share/python:$PATH $ easy_install pip pip install numpy pip install gcc pip install scipy brew install pkg-config pip install matplotlib I just solved the issue by doing the following: I open my 2.7.11 python >>> import sys >>> sys.path.insert(0, ‘/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python’) and that fixed it! Thanks a lot for your help!

Источник

How to install matplotlib for particular version of Python?

I have installed scipy and numpy, and they are being used with my current, desired version of python 2.7.6 (I am running on OSX Mavericks and had to upgrade.) However, when I pip installed matplotlib, by default it referenced my previous python version, 2.7.5, thus making it troublesome to use (obviously.) How do I change which version of python matplotlib uses so I can import and use the library?
Thanks.

2 Answers 2

The way I would solve this problem is like this, firstly one would need to go into your 2.7.6 directory, and under the Scripts folder you will find the pip executable. My suggestion is (because its difficult to debug this kind of people without having all the details) is this:

And see if this succeeds, otherwise, I suggest using pyenv to manage your python installations.

I suggest you use Macports for installing additional Python versions on OS X. Once Macports is installed, it’s fairly easy to install Python 2.7.6. All you’d have to do is:

sudo port install python27 

Now, you should be able to get all the libraries you need just as easily, using, too, Macports.

sudo port install py27-numpy sudo port install py27-scipy sudo port install py27-matplotlib 

Macports should solve all the dependencies and, of course, link the packages to their correct Python versions, avoiding you a lot of headaches.

Источник

Читайте также:  Основные алгоритмические конструкции питон
Оцените статью