下载并解压:
1 wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz 2 tar -xzvf Python-3.7.2.tgz
进入目录:
cd Python-3.7.2
编译:
./configure --prefix=/usr/local/python3
安装:
make
make insatll
缺少依赖包导致:
执行:yum -y install zlib* 安装依赖包即可
仍缺少组件,无法导入_ctypes模块:
1 yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel 2 yum install libffi-devel -y
https://cpython-devguide.readthedocs.io/setup/#build-dependencies
注意:此步骤安装完成之后,需要重新编译文件
安装完成之后,python已经安装成功,但是需要配置环境变量,(如果不想配置环境变量可以在编译那一步将 --prefix=/usr/local/python3 这一部分去掉【没有测试】
)
创建软连接即可,
1 [root@bing ~]# mv /usr/bin/python /usr/bin/python_bak 2 [root@bing ~]# ln -s /usr/local/python3/bin/python3 /usr/bin/python 3 [root@bing ~]# python 4 Python 3.7.2 (default, Feb 23 2019, 19:05:50) 5 [GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux 6 Type "help", "copyright", "credits" or "license" for more information. 7 >>> exit()
pip还无法使用
1 [root@bing ~]# PATH=$PATH:$HOME/bin: 2 [root@bing ~]# PATH=$PATH:$HOME/bin:/usr/local/python3/bin
配置完环境变量(在本次会话中)即可使用pip,最好是创建软连接
续;
安装过程中出现:pip is configured with locations that require TLS/SSL, however the ssl modul
#重新编译安装
./configure --prefix=/usr/local/python3 --enable-optimizations --with-ssl
make
make install
#重新第三方库pymysql
pip3 intall pymysql