python3.5 源码安装走过的坑

报错一 python3.5 使用压缩的时候提示没有zlib模块。

1
2
3
4
5
6
7
  File "1.py", line 6, in <module>
tar = tarfile.open("sample.tar.gz", "w:gz")
File "/usr/local/python3/lib/python3.5/tarfile.py", line 1580, in open
return func(name, filemode, fileobj, **kwargs)
File "/usr/local/python3/lib/python3.5/tarfile.py", line 1624, in gzopen
raise CompressionError("gzip module is not available")
tarfile.CompressionError: gzip module is not available

解决办法

先按照zlib模块,在编译安装

1
2
3
4
5
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel -y

./configure --prefix=/data/app/python-3.5.2 --enable-shared
make
make install

执行命令继续报错

1
python3: error while loading shared libraries: libpython3.5m.so.1.0: cannot open shared object file: No such file or directory

解决办法

1
2
echo /data/app/python3/lib/ >> /etc/ld.so.conf.d/local.conf
ldconfig