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:
-
is a folder that you have some Python code using matplotlibyour_repo
-
is a folder created usingvenv
; you’ll activate the virtualenv in thevirtualenv venv
folder using theyour_repo
command. venv/bin/activate
-
contains a line to installrequirements.txt
. For me, this line ismatplotlib
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