Installing matplotlib and its dependencies without

2019-04-19 14:49发布

I want to use matplotlib on a server where I have an account /myhome without root privileges.

I downloaded the matplotlib sources and tried to install it using the distutils with the user sheme, say python setup.py install --user, but it returned the following message :

============================================================================
Edit setup.cfg to change the build options

BUILDING MATPLOTLIB
        matplotlib: yes [1.3.1]
            python: yes [2.7.3 (default, Jan  2 2013, 13:56:14)  [GCC
                    4.7.2]]
          platform: yes [linux2]

REQUIRED DEPENDENCIES AND EXTENSIONS
             numpy: yes [version 1.6.2]
          dateutil: yes [using dateutil version 1.5]
           tornado: yes [tornado was not found. It is required for the
                    WebAgg backend. pip/easy_install may attempt to
                    install it after matplotlib.]
         pyparsing: yes [pyparsing was not found. It is required for
                    mathtext support. pip/easy_install may attempt to
                    install it after matplotlib.]
             pycxx: yes [Couldn't import.  Using local copy.]
            libagg: yes [pkg-config information for 'libagg' could not
                    be found. Using local copy.]
          freetype: no  [pkg-config information for 'freetype2' could
                    not be found.]
               png: yes [pkg-config information for 'libpng' could not
                    be found. Using unknown version.]

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]

OPTIONAL BACKEND EXTENSIONS
            macosx: no  [Mac OS-X only]
            qt4agg: yes [installing, Qt: 4.8.2, PyQt4: 4.9.3]
           gtk3agg: yes [installing, version 3.2.4]
         gtk3cairo: yes [installing, version 3.2.4]
            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, version 1.8.8]
         windowing: no  [Microsoft Windows only]

OPTIONAL LATEX DEPENDENCIES
            dvipng: yes [version 1.14]
       ghostscript: yes [version 9.05]
             latex: yes [version 3.1415926]
           pdftops: yes [version 0.18.4]

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

It seemed that the package 'freetype' was missing, so I downloaded its sources, and I found that it could be installed in a specific place by running:

./configure --prefix=/myhome/somedir
make
make install

My question is: where do I install freetype so it can be detected by the distutils ?

My first thought was to install it in /myhome/.local because this is where the distutils install a module when using the --user option. Unfortunately, when doing this, I still got the same message as above.

I tried something more complicated by creating a virtual environment using the virtualenv package :

virtualenv /myhome/venv/

Then I installed freetype in myhome/venv/ and finally I ran the distutils within this virtual environnement, but it gave me the same message again.

Thank you for helping, and, of course, I won't ask my sysadmin to install matplotlib for me.

PS: something certainly unrelated with my problem but maybe worth noting : I install the freetype package by using ./configure --prefix=/myhome/somedir --without-png. Without the --without-png option, I get the following error:

checking for libpng... configure: error: `libpng-config' not found;
either set the LIBPNG_CFLAGS and LIBPNG_LDFLAGS environment variables,
or pass `--without-png' to the `configure' script.

6条回答
劳资没心,怎么记你
2楼-- · 2019-04-19 15:17

You should install system requirements, and it doesn't not related to python, pip, virtualenv.

To install the requirements, please refer this. https://stackoverflow.com/a/20533455/2962018

In a nutshell,

Ubuntu/Debian

apt-get install libfreetype6-dev

Redhat

yum -y install freetype-devel

OSX

brew install freetype

After installing freetype, try

pip install matplotlib
查看更多
欢心
3楼-- · 2019-04-19 15:19

From what I can see, matplot setup will eventually call the prompt with

pkg-config freetype2 --modversion 

to try and find the package. It seems like it fails on this call.

Try to see what error that command gives you and let us know. See http://people.freedesktop.org/~dbn/pkg-config-guide.html for more info on pkg-config. It's possible on some systems that pkg-config is not installed.

UPDATE: From what I can get from the matplotlib setup files, it'll search for ft2build.h in subdirectories include, lib and lib64 in the directories /usr/local and in /usr.

You can find the needed source files for freetype at http://www.freetype.org/developer.html (you'll need the .h files, but it won't hurt to get all of them).

In case you don't have access to any of these directories, you can add directories for it to search in by editing the directories entry in setup.cfg for matplotlib.

Should you not be able to edit the setup.cfg file, you can also try to edit the setupext.py file in your matplotlib directory directly. In line 95, there is a function get_base_dirs, you could edit this function to return extra directories for it to search in (it'll look for subdirectories include, lib and lib64 in those added directories).

查看更多
淡お忘
4楼-- · 2019-04-19 15:26

I had got the same error while installing matplotlib. Installing pkg-config worked for me. Try the following command for ubuntu:

sudo apt-get install pkg-config
查看更多
姐就是有狂的资本
5楼-- · 2019-04-19 15:37

Specifically for mac: I had similar issue in installing the matplotlib. Follow these instructions and you are done:

  1. Install python3 using brew. ( Ignore this step if you already have it) Note: To install brew.

    brew install python3
    
  2. Install freetype :

    brew install freetype
    
  3. Now install pkg-config using pip3:

    brew install pkg-confi
    
  4. Finally install matplotlib:

    sudo pip3 install matplotlib
    
查看更多
Emotional °昔
6楼-- · 2019-04-19 15:40

Based on some suggestions here and other instructions on the internet, the following recipe worked for me:

 wget http://download.savannah.gnu.org/releases/freetype/freetype-2.5.3.tar.gz
 tar xzf freetype-2.5.3.tar.gz
 cd freetype-2.5.3
 ./configure --prefix=/myhome/local --without-png
 make && make install
 export PKG_CONFIG_PATH=/myhome/local/lib/pkgconfig
 pip install matplotlib --upgrade
查看更多
乱世女痞
7楼-- · 2019-04-19 15:41

May be very late now, but I just faced same issue while installing matplotlib inside virtualenv created using virtualenvwrapper.

These instructions worked for me: http://newcoder.io/dataviz/part-0/

查看更多
登录 后发表回答