Centos7下的Python3.7安装
程序员文章站
2024-03-08 20:09:22
...
安装
- 相关依赖下载
sudo yum -y install wget zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
- python3.7安装
安装python3.7及以上版本直接安装会报错:
ModuleNotFoundError: No module named '_ctypes'
需先安装libffi-devel,在安装新版本python前可直接通过yum安装
sudo yum install libffi-devel -y
若已经编译,yum还未重新配置无法正常使用,则通过wget自行下载安装包
wget http://mirror.centos.org/centos/7/os/x86_64/Packages/libfontenc-devel-1.1.3-3.el7.x86_64.rpm
rpm -ivh libffi-devel-3.0.13-18.el7.x86_64.rpm
安装python3.8
wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4rc1.tgz
tar -xvf Python-3.7.4rc1.tgz
mv Python-3.7.4rc1 python3
cd python3
./configure --prefix=/home/python3
make
make install
配置软链接
- pip
备份原软链接
sudo mv python python.bk
sudo mv pip pip.bk
创建新版本python软链接
sudo ln -s /home/python3/bin/python3 /usr/bin/python
sudo ln -s /home/python3/bin/pip3 /usr/bin/pip
- yum
修改完python软链接后yum无法正常使用,需要重新配置
sudo vim /usr/bin/yum
#!/usr/bin/python 改为 #!/usr/bin/python2.7
测试
python
sudo yum search pip