Python 在没有 root 权限的情况下安装 matplotlib 及其依赖项

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20904841/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 21:29:57  来源:igfitidea点击:

Installing matplotlib and its dependencies without root privileges

pythonmatplotlibmoduleinstallationdependencies

提问by user3156933

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

我想在我有一个/myhome没有 root 权限的帐户的服务器上使用 matplotlib 。

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 :

我下载了 matplotlib 源代码并尝试使用带有用户 sheme 的 distutils 安装它,例如python setup.py install --user,但它返回以下消息:

============================================================================
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:

似乎缺少“freetype”包,所以我下载了它的源代码,发现可以通过运行以下命令将其安装在特定位置:

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

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

我的问题是:我在哪里安装 freetype 以便它可以被 distutils 检测到?

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

我的第一个想法是安装它,/myhome/.local因为这是使用--user选项时 distutils 安装模块的地方。不幸的是,在执行此操作时,我仍然收到与上述相同的消息。

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

我通过使用 virtualenv 包创建虚拟环境尝试了更复杂的事情:

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.

然后我安装了 freetype,myhome/venv/最后我在这个虚拟环境中运行了 distutils,但它再次给了我同样的消息。

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

谢谢你的帮助,当然,我不会让我的系统管理员为我安装 matplotlib。

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-pngoption, I get the following error:

PS:肯定与我的问题无关,但可能值得注意的是:我使用./configure --prefix=/myhome/somedir --without-png. 如果没有该--without-png选项,我会收到以下错误:

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.

回答by HSquirrel

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

据我所知,matplot setup 最终会调用提示

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.htmlfor more info on pkg-config. It's possible on some systems that pkg-config is not installed.

尝试查看该命令给您带来的错误并告诉我们。有关pkg-config 的更多信息,请参阅http://people.freedesktop.org/~dbn/pkg-config-guide.html。在某些系统上可能未安装 pkg-config。

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.

更新:根据我从 matplotlib 安装文件中获得的信息,它将在 /usr/local 和 /usr 目录中的子目录 include、lib 和 lib64 中搜索 ft2build.h。

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).

您可以在http://www.freetype.org/developer.html找到所需的 freetype 源文件(您将需要 .h 文件,但获得所有这些文件也无妨)。

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.

如果您无权访问这些目录中的任何一个,您可以通过编辑 setup.cfg 中 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).

如果您无法编辑 setup.cfg 文件,您也可以尝试直接编辑 matplotlib 目录中的 setupext.py 文件。在第 95 行,有一个函数 get_base_dirs,您可以编辑此函数以返回额外的目录供它搜索(它将在这些添加的目录中查找子目录 include、lib 和 lib64)。

回答by HSquirrel

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

回答by Deep

May be very late now, but I just faced same issue while installing matplotlibinside virtualenvcreated using virtualenvwrapper.

可能是很晚了,但我只是遇到同样的问题,在安装matplotlibvirtualenv使用的创作virtualenvwrapper

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

这些说明对我有用http: //newcoder.io/dataviz/part-0/

回答by MiaeKim

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

你应该安装系统要求,它与python、pip、virtualenv无关。

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

要安装要求,请参阅此。 https://stackoverflow.com/a/20533455/2962018

In a nutshell,

简而言之,

Ubuntu/Debian

Ubuntu/Debian

apt-get install libfreetype6-dev

Redhat

红帽

yum -y install freetype-devel

OSX

操作系统

brew install freetype

After installing freetype, try

安装freetype后,尝试

pip install matplotlib

回答by amulya349

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

我在安装 matplotlib 时遇到了同样的错误。安装 pkg-config 对我有用。为 ubuntu 尝试以下命令:

sudo apt-get install pkg-config

回答by Kripson21

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

专门针对 mac:我在安装 matplotlib 时遇到了类似的问题。按照以下说明操作即可完成:

  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
    
  1. 使用 brew 安装 python3。(如果你已经有了这一步,请忽略) 注意:安装 brew。

    brew install python3
    
  2. 安装自由类型:

    brew install freetype
    
  3. 现在使用 pip3 安装 pkg-config:

    brew install pkg-confi
    
  4. 最后安装 matplotlib:

    sudo pip3 install matplotlib