安装python3.6需要依赖zlib包,所有安装如下:
root@:~# cd /usr/lib/install
root@:/usr/lib/install 我们先下载zlib (如果安装了nginx可跳过,nginx同样需要依赖zlib)
root@:/usr/lib/install# wget http://zlib.net/zlib-1.2.11.tar.gz
root@:/usr/lib/install# tar xzf zlib-1.2.11.tar.gz
root@:/usr/lib/install# cd zlib-1.2.11/
root@:/usr/lib/install 编译并安装zlib
root@:/usr/lib/install/zlib-1.2.11# ./configure && make && make install
root@:/usr/lib/install/zlib-1.2.11# sudo apt-get update
root@:/usr/lib/install/zlib-1.2.11# sudo apt-get upgrade
root@:/usr/lib/install/zlib-1.2.11 安装openssl,ubuntun自带openssl,可省略此命令
root@:/usr/lib/install/zlib-1.2.11# sudo apt-get install openssl
root@:/usr/lib/install/zlib-1.2.11 安装openssl依赖ssl包,如果不安装,python无法执行https请求
root@:/usr/lib/install/zlib-1.2.11# sudo apt-get install libssl-dev
root@:/usr/lib/install/zlib-1.2.11# cd ../
root@:/usr/lib/install# wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgztar xzf Python-3.6.0.tgz
root@:/usr/lib/install# tar xzf Python-3.6.0.tgz
root@:/usr/lib/install# cd Python-3.6.0/
root@:/usr/lib/install/Python-3.6.0 编译python3.6
root@:/usr/lib/install/Python-3.6.0# ./configure --enable-loadable-sqlite-extensions --prefix=/usr/local/python3
root@:/usr/lib/install/Python-3.6.0 安装python3.6
root@:/usr/lib/install/Python-3.6.0# make && make install
root@:/usr/lib/install/Python-3.6.0 做软连接(相当于windows快捷方式)
root@:/usr/lib/install/Python-3.6.0# ln -s /usr/local/python3/bin/python3.6 /usr/local/bin/python3
root@:/usr/lib/install/Python-3.6.0# ln -s /usr/local/python3/bin/pip3.6 /usr/local/bin/pip
root@:/usr/lib/install/Python-3.6.0 文件已存在,ubuntu自带的python
ln: failed to create symbolic link '/usr/local/bin/pip': File exists
root@:/usr/lib/install/Python-3.6.0# cd /usr/local/bin/
root@:/usr/local/bin 删除python自带的pip(备份一下比较好)
root@:/usr/local/bin# rm pip
root@:/usr/local/bin 做软链接(为什么要做软连接?当你在命令行敲python或python3或pip install xx时,会在/usr/local/bin或/usr/bin目录下执行文件名为python或python3或pip)
root@:/usr/local/bin# ln -s /usr/local/python3/bin/pip3.6 /usr/local/bin/pip
root@:/usr/local/bin 升级pip到最新的版本
root@:/usr/local/bin# pip install --upgrade pip
root@:/usr/local/bin 安装需要的块,需要用到就安装
root@:/usr/local/bin# pip install requests
root@:/usr/local/bin# pip install itchat
root@:/usr/local/bin# pip install pyOpenSSL
到此,安装结束,输入:python3 可以看到python版本,如果不是自己安装的版本就重启:shutdown -r now
重启后看到的不是自己安装python那就做软链接:
ln -s /usr/local/python3/bin/python3.6 /usr/local/bin/python3
输入:python3,ubuntu默认是去/usr/local/bin目录查询python3并执行,如果没找到会去/usr/bin目录查询python3并执行
,2个目录都没有python3文件就抛异常