在安装ubuntu安装matplotlib时碰到不少问题,简单做个备忘:

需要先安装其依赖的包libpng和freetype

安装libpng:

 

sudo apt-get install libpng-dev

安装freetype:

 

cd ~/Downloads

wget https://download.savannah.gnu.org/releases/freetype/freetype-2.4.10.tar.gz

tar zxvf freetype-2.4.10.tar.gz

cd freetype-2.4.10/

./congfigure

make

sudo make install

安装pip,然后通过pip来安装matplotlib: 

sudo apt-get install python-pip

 

安装好pip后就可以用下面的命令来查找matplotlib和查看其安装状态

sudo pip search matplotlib

 

安装matplotlib

sudo pip install matplotlib

 

1.no module named configparser

pip install configparser 

或 sudo aptitude install python-configparser

 

出现这个问题的原因是python3中并没有ConfigParser这个模块,为了遵循pep 8的标准,已经改名为configparser了。

通过报错可以看到出问题的文件在哪里,我们切换到该文件所在文件夹,我的是/usr/bin/。如果通过一般的思维,即把该文件中的语法转化为python3,那么可以解决这个问题,但是又会报出其它错误,可以照错误提示一直把全部相关文件和模块改为python3的语法,但是工作量很繁琐。

另外一种方法:通过ls我们可以看到有个文件叫做pycompile,还有个文件叫做py3compile,前者遵循的是python2的语法,而我们使用pip的时候使用的就是pycompile,我们只需要用py3compile中的内容覆盖pycompile中的内容,这样的话就解决这个问题了

备注:以上是我在使用ubuntu16.04安装和使用pip发现的问题,ubuntu16.04测试成功

 

2. fatal error: Python.h: No such file or directory

For Python version 2.x+

$ sudo apt-get install python-dev

OR
# apt-get install python-dev
For Python version 3.x+

$ sudo apt-get install python3-dev

OR
# apt-get install python3-dev

 

注意在实际画图中仍然可能出错,错误是“NotImplementedError: Surface.create_for_data: Not Implemented yet.”

可以通过安装cairocffi解决。

sudo pip3 install cairocffi。

安装cairocffi也会碰到错误,可以尝试:

sudo apt-get install python3-dev
sudo apt-get install libffi-dev
sudo pip3 install cffi
sudo pip3 install cairocffi


pip install cairocffi==0.6
 

 

分类:

技术点:

相关文章: