服务器和python官网是不通的,所以采取手动安装方式
重点:
1.下载依赖库,压缩包解压一个装一个,不然最后都分不清哪个已经装了。。。
如果是手动安装,仅安装Matplotlib是不够的,就还需要安装six,cycler,kiwisolver,numpy,pyparsing,python_dateutil,pytz等依赖库才可以。
2.安装时候根据报错去找包,可以去python官网,但是有的包找不到这时可以去找对应的源码包从ftp服务器上下载(一般官网有链接)
(1)python官网下载tar.gz或zip等,解压后进入目录执行 python3 setup.py install
(2)python官网没有找到libffi和libpng,后者block了matplotlib的安装
libffi ftp://sourceware.org/pub/libffi
step 1 解压
如果用 tar -xzvf 报错如下,则改用 tar -xvf xxx
# tar -xzvf libffi-3.2.1.tar.gz
gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now
step2 编译安装
进入解压后路径执行如下命令
./configure -> make -> sudo make install
libpng官网 http://www.libpng.org/pub/png/libpng.html 下了几个压缩包解压出来有问题,最终找到以下这个OK
表格Beta Code一栏中 https://libpng.sourceforge.io/index.html
打开的新页面中找到这个链接(描述中后面那个更快的没有试)
The previous ftp site is still being maintained at ftp://ftp.simplesystems.org/pub/png, but the OSUOSL site is much faster and has a more complete archive of old versions.
ftp://ftp.simplesystems.org/pub/png/src/libpng16/ 找到tar.gz下载
3.执行matplotlib安装时的一些报错的解决
(1) 如下,少了libpng,去下载然后安装
[root@xxx matplotlib-3.0.3]# python3 setup.py install
============================================================================
...
install_requires: yes [handled by setuptools]
libagg: yes [pkg-config information for 'libagg' could not
be found. Using local copy.]
freetype: yes [version 2.3.11]
png: no [pkg-config information for 'libpng' could not
be found.]
qhull: yes [pkg-config information for 'libqhull' could not
be found. Using local copy.]
...
============================================================================
* The following required packages can not be built:
* png
(2)如下,没有安装gcc++,因为用的是本地yum源,所以用yum安装一下
参考:https://www.cnblogs.com/skyme/archive/2011/01/19/1939606.html
gcc: error trying to exec 'cc1plus': execvp: No such file or directory
error: command 'gcc' failed with exit status 1
可能是gcc和g++版本不兼j容,也可能是安装完gcc没有安装g++
查看版本,发现没有安装gcc++
# gcc -v
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC)
# gcc++ -v
-bash: gcc++: command not found
执行yum命令安装 # yum --disablerepo=* --enablerepo=MEDIA install gcc-c++
(3)如下,先安装版本>=2.1的python-dateutil(其实下载解压了但是下的包太多了,这个漏了安装)
Download error on https://pypi.org/simple/: [Errno -3] Temporary failure in name resolution -- Some packages may not be found!
No local packages or working download links found for python-dateutil>=2.1
error: Could not find suitable distribution for Requirement.parse('python-dateutil>=2.1')
然后安装python-dateutil又有报错,先去python官网下载个setuptools_scm安装
Download error on https://pypi.org/simple/setuptools_scm/: [Errno -3] Temporary failure in name resolution -- Some packages may not be found!
Download error on https://pypi.org/simple/setuptools-scm/: [Errno -3] Temporary failure in name resolution -- Some packages may not be found!
Couldn't find index page for 'setuptools_scm' (maybe misspelled?)
Download error on https://pypi.org/simple/: [Errno -3] Temporary failure in name resolution -- Some packages may not be found!
No local packages or working download links found for setuptools_scm
Traceback (most recent call last):
...
distutils.errors.DistutilsError: Could not find suitable distribution for Requirement.parse('setuptools_scm')
最后终于成功安装matplotlib了(试着import matplotlib没问题)
[root@xxx matplotlib-3.0.3]# python3 setup.py install
......
Finished processing dependencies for matplotlib==3.0.3
[root@xxx matplotlib-3.0.3]# python3
Python 3.6.8 (default, Apr 9 2019, 18:09:49)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
>>>
>>> exit()
=========================================
使用matplotlib遇到的问题
# python3
Python 3.6.8 (default, Apr 9 2019, 18:09:49)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot as plt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/testpy3/python3/lib/python3.6/site-packages/matplotlib-3.0.3-py3.6-linux-x86_64.egg/matplotlib/pyplot.py", line 32, in <module>
import matplotlib.colorbar
File "/opt/testpy3/python3/lib/python3.6/site-packages/matplotlib-3.0.3-py3.6-linux-x86_64.egg/matplotlib/colorbar.py", line 32, in <module>
import matplotlib.contour as contour
File "/opt/testpy3/python3/lib/python3.6/site-packages/matplotlib-3.0.3-py3.6-linux-x86_64.egg/matplotlib/contour.py", line 19, in <module>
import matplotlib.text as text
File "/opt/testpy3/python3/lib/python3.6/site-packages/matplotlib-3.0.3-py3.6-linux-x86_64.egg/matplotlib/text.py", line 18, in <module>
from .textpath import TextPath # Unused, but imported by others.
File "/opt/testpy3/python3/lib/python3.6/site-packages/matplotlib-3.0.3-py3.6-linux-x86_64.egg/matplotlib/textpath.py", line 12, in <module>
from matplotlib.mathtext import MathTextParser
File "/opt/testpy3/python3/lib/python3.6/site-packages/matplotlib-3.0.3-py3.6-linux-x86_64.egg/matplotlib/mathtext.py", line 34, in <module>
from matplotlib import _png, cbook, colors as mcolors, get_data_path, rcParams
ImportError: libpng16.so.16: cannot open shared object file: No such file or directory
解决:
libpng的安装目录下配置动态链接
# echo "/usr/local/lib" >> /etc/ld.so.conf
# cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
/usr/local/lib
# cd libpng-1.6.34
# sudo ldconfig
########################################################
pygal安装之前要安装pytest-runner
1.python官网下载pytest-runner和pygal
2.安装pytest-runner,再安装pygal (python3 setup.py install)