1、下载安装包
wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tar.xz
2、解压
tar -xvJf Python-3.7.2.tar.xz
3、创建编译安装目录
mkdir /usr/local/python3
4、编译和安装
cd Python-3.7.2
./configure --prefix=/usr/local/python3 --enable-optimizations --with-ssl
#第一个指定安装的路径,不指定的话,安装过程中可能软件所需要的文件复制到其他不同目录,删除软件很不方便,复制软件也不方便.
#第二个可以提高python10%-20%代码运行速度.
#第三个是为了安装pip需要用到ssl,后面报错会有提到.
make && make install
5、创建软连接
ln -s /usr/local/python3/bin/python3 /usr/local/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip3
6、测试
python
pip list
7、错误
zipimport.ZipImportError: can't decompress data; zlib not available
1、yum -y install zlib* yum -y install libffi-devel
2、 解压包中 vim Python-3.7/Modules/Setup
# Andrew Kuchling's zlib module. # This require zlib 1.1.3 (or later). # See http://www.gzip.org/zlib/ zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz # Interface to the Expat XML parser # More information on Expat can be found at www.libexpat.org. # #pyexpat expat/xmlparse.c expat/xmlrole.c expat/xmltok.c pyexpat.c -I$(srcdir)/Modules/expat -DHAVE_EXPAT_CONFIG_H -DXML_POOR_ENTROPY=1 -DUSE_PYEXPAT_CAPI
配置 pip 源
cd ~ mkdir .pip cd .pip vim pip.conf #进入后添加以下内容,保存退出. [global] index-url = https://mirrors.aliyun.com/pypi/simple