新安装的Centos7,不对本身的Pyhon2做任何更改,也不建议做更改
0.升级
//先升一下级
yum update
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 libffi-devel python-dev python3-dev
//PS:有时候不知道这么多依赖都有什么用,但是全部安装总不会错,避免后续用pip安装模块时报各种各样的错误
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 libffi-devel python-dev python3-dev
//PS:有时候不知道这么多依赖都有什么用,但是全部安装总不会错,避免后续用pip安装模块时报各种各样的错误
2.在python官网找到自己需要的python包下载至本地
//不管采用哪种下载方式,总之要下载到Centos系统中某个文件夹下
//方式一:
wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tar.xz
//方式二:
curl –o https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tar.xz
//等等其他方式
3.解压
//解压
tar -xvJf Python-3.7.3.tar.xz
//切换进入
cd Python-3.7.3
4.编译安装
//编译安装
./configure prefix=/usr/local/python3 //等待编译完成
//再次输入
make && make install
//PS:如果安装中出现 “ModuleNotFoundError: No module named '_ctypes'
//的错误那是因为并未安装“libffi-devel” 3.7版本需要一个新的包libffi-devel,
//安装此包之后再次进行编译安装即可。
5创建Python3的软链接
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
6.记得升级python2的pip
python -m pip install -U pip
7.测试命令 python3 和 pip3
[root@192 ptext]# python -V
Python 2.7.5
[root@192 ptext]# python3 -V
Python 3.7.3
[root@192 ptext]# pip3 -V
pip 19.0.3 from /usr/local/python3/lib/python3.7/site-packages/pip (python 3.7)
[root@192 ptext]# pip2 -V
pip 19.0.3 from /usr/lib/python2.7/site-packages/pip (python 2.7)
[root@192 ptext]#
网友评论