web-dev-qa-db-fra.com

Comment installer Matplotlib dans Ubuntu 14.04?

La motivation en 14.04: 16.04 est un buggy pour une utilisation en production. 14.04 est le seul stable. 15.10 est aussi un buggy. Leur mise à jour/système avec runit est horrible.

Je lance masi@masi:~/BitTorrentSync/IPython$ Sudo -H pip install matplotlib

Collecting matplotlib
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#snimissingwarning.
  SNIMissingWarning
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading matplotlib-1.5.1.tar.gz (54.0MB)
    100% |████████████████████████████████| 54.0MB 26kB/s 
    Complete output from command python setup.py Egg_info:
    ============================================================================
    Edit setup.cfg to change the build options

    BUILDING MATPLOTLIB
                matplotlib: yes [1.5.1]
                    python: yes [2.7.6 (default, Jun 22 2015, 17:58:13)  [GCC
                            4.8.2]]
                  platform: yes [linux2]

    REQUIRED DEPENDENCIES AND EXTENSIONS
                     numpy: yes [version 1.11.0]
                  dateutil: yes [using dateutil version 2.5.3]
                      pytz: yes [using pytz version 2016.4]
                    cycler: yes [cycler was not found. pip will attempt to
                            install it after matplotlib.]
                   tornado: yes [using tornado version 4.3]
                 pyparsing: yes [pyparsing was not found. It is required for
                            mathtext support. pip/easy_install may attempt to
                            install it after matplotlib.]
                    libagg: yes [pkg-config information for 'libagg' could not
                            be found. Using local copy.]
                  freetype: no  [The C/C++ header for freetype2 (ft2build.h)
                            could not be found.  You may need to install the
                            development package.]
                       png: no  [pkg-config information for 'libpng' could not
                            be found.]
                     qhull: yes [pkg-config information for 'qhull' could not be
                            found. Using local copy.]

    OPTIONAL SUBPACKAGES
               sample_data: yes [installing]
                  toolkits: yes [installing]
                     tests: yes [nose 0.11.1 or later is required to run the
                            matplotlib test suite. Please install it with pip or
                            your preferred tool to run the test suite / mock is
                            required to run the matplotlib test suite. Please
                            install it with pip or your preferred tool to run
                            the test suite]
            toolkits_tests: yes [nose 0.11.1 or later is required to run the
                            matplotlib test suite. Please install it with pip or
                            your preferred tool to run the test suite / mock is
                            required to run the matplotlib test suite. Please
                            install it with pip or your preferred tool to run
                            the test suite]

    OPTIONAL BACKEND EXTENSIONS
                    macosx: no  [Mac OS-X only]
                    qt5agg: no  [PyQt5 not found]
                    qt4agg: yes [installing, Qt: 4.8.6, PyQt: 4.8.6; PySide not
                            found]
                   gtk3agg: yes [installing, version 3.8.10]
                 gtk3cairo: yes [installing, version 3.8.10]
                    gtkagg: no  [The C/C++ header for gtk (gtk/gtk.h) could not
                            be found.  You may need to install the development
                            package.]
                     tkagg: no  [TKAgg requires Tkinter.]
                     wxagg: no  [requires wxPython]
                       gtk: no  [The C/C++ header for gtk (gtk/gtk.h) could not
                            be found.  You may need to install the development
                            package.]
                       agg: yes [installing]
                     cairo: yes [installing, pycairo version 1.8.8]
                 windowing: no  [Microsoft Windows only]

    OPTIONAL LATEX DEPENDENCIES
                    dvipng: no
               ghostscript: yes [version 9.10]
                     latex: no
                   pdftops: yes [version 0.24.5]

    OPTIONAL PACKAGE DATA
                      dlls: no  [skipping due to configuration]

    ============================================================================
                            * The following required packages can not be built:
                            * freetype, png

    ----------------------------------------
Command "python setup.py Egg_info" failed with error code 1 in /tmp/pip-build-5VdgT2/matplotlib/

le code d'erreur 1 n'a renvoyé aucun thread correspondant. J'ai eu exactement la même erreur lors de l'exécution de la commande sans Sudo -H. Ceci est une installation incomplète, en essayant d'utiliser le module que vous obtenez

ImportError: No module named matplotlib.pyplot

Proposition en commentaire. Je lance Sudo apt-get install libfreetype6-dev libpng12-dev avec succès. Je lance avec succès Sudo -H pip install matplotlib. Cependant, je reçois l'avertissement lorsque j'exécute maintenant le module matplotlib

/usr/local/lib/python2.7/dist-packages/matplotlib/font_manager.py:273: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment.
  warnings.warn('Matplotlib is building the font cache using fc-list. This may take a moment.')

Comment installer matplotlib dans Ubuntu 14.04?

Le commentaire d'Edwinksl et thread . Le dernier avertissement est l'avertissement du cache de polices. Lancez ipython pour connaître le répertoire de cache de Matplotlib.

In [2]: import matplotlib
In [3]: matplotlib.get_cachedir()
Out[3]: u'/home/masi/.cache/matplotlib'

Dans mon cas, supprimer

rm /home/masi/.cache/matplotlib/fontList.cache 
rm -r /home/masi/.cache/matplotlib/tex.cache/

Maintenant, exécutez à nouveau votre code de test matplotlib. J'ai eu la même erreur à la première manche. Je lance le code de test une seconde fois, et le cas a été résolu. La proposition d'Edwinksl pourquoi il a le comportement

Je devine que la première itération est en effet la construction des caches puisqu'elles n'existent pas. À la deuxième itération, matplotlib sait que les caches existent, il ne faut donc pas les reconstruire.