天天看點

如何在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

繼續閱讀