如何在Ubuntu的虚拟环境(virtualenv )下安装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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值