美文网首页
Ubuntu16.04 从源码安装并升级python版本为3.6

Ubuntu16.04 从源码安装并升级python版本为3.6

作者: LeslieLiang | 来源:发表于2020-01-15 13:42 被阅读0次

1. 下载python3.6源码包

wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz

2. 解压并开始安装

apt-get install -y openssl-devel libssl-devel

修改Modules/Setup.dist文件, 找到下面的内容并照着取消注释 (import ssl 提示无法找到包问题)

# Socket module helper for socket(2)
_socket socketmodule.c
# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
SSL=/usr/local/ssl
_ssl _ssl.c \
        -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
        -L$(SSL)/lib -lssl -lcrypto
tar -xvf Python-3.6.5.tgz
cd Python-3.6.5/
./configure --prefix=/opt
make && make install

安装时可能会报错提示 zipimport.ZipImportError: can't decompress data; zlib not available, 则需要安装zlib解压缩类库 apt-get install -y zlib*

3. 替换python3为python3.6

update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 1
update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.6 2
update-alternatives --config python3

4. 解决pip3安装问题

替换版本之后 pip3 install 时会提示错误subprocess.CalledProcessError: Command 'lsb_release -a' returned non-zero exit status 1., 重点关注lsb_release.py这个模块
我们将python3.5中的lsb_release.py复制到python3.6中

root@ubuntu:~# find / -name 'lsb_release.py'
/usr/lib/python2.7/dist-packages/lsb_release.py
/usr/lib/python3/dist-packages/lsb_release.py
/usr/share/pyshared/lsb_release.py
root@ubuntu:~# cp /usr/lib/python3/dist-packages/lsb_release.py /usr/local/lib/python3.6/

相关文章

网友评论

      本文标题:Ubuntu16.04 从源码安装并升级python版本为3.6

      本文链接:https://www.haomeiwen.com/subject/lvdtzctx.html