天天看点

如何在Ubuntu的虚拟环境(virtualenv )下安装matplotlib1/本文的关键在于在ubuntu的虚拟环境中安装matplotlib

1/本文的关键在于在ubuntu的虚拟环境中安装matplotlib

  • 我的ubuntu自带python2.7
  • 通过在虚拟环境中用pip命令安装报错 命令:pip install python-matplotlib
  • 查了一下错误原因是:构建Matplotlib需要libpng(和freetype,也不是python库),因此pipdoes不会处理安装它(或freetype)。
  • 如果不在虚拟环境其实我们可以通过 命令:sudo apt-get install python-matplotlib 来安装最新版本的matplotlib
  • 但是我们想要安装的matplotlib在虚拟环境中,所以 apt-get的方法显然不可以
  • 解决方案:

Assumptions

We’ll be installing matplotlib 1.4.3 .

We assume that there is the following folder hierarchy somewhere on your system:

your_repo
|--- requirements.txt
|--- venv
      

where:

  • your_repo

    is a folder that you have some Python code using matplotlib
  • venv

    is a folder created using

    virtualenv venv

    ; you’ll activate the virtualenv in the

    your_repo

    folder using the

    . venv/bin/activate

    command
  • requirements.txt

    contains a line to install

    matplotlib

    . For me, this line is

    matplotlib==1.4.3

Commands to run

sudo apt-get -y build-dep matplotlib
cd your_repo
. venv/bin/activate
pip install -r requirements.txt
      

上面的那个requirements.txt这就是一个写了

matplotlib==1.4.3

的文本文件,搜一下就知道是干什么的了

其实最重要的就是

sudo apt-get -y build-dep matplotlib这句话

原文在这:

https://yanhan.github.io/posts/2015-07-25-how-to-install-matplotlib-using-virtualenv-on-ubuntu.html

继续阅读