第十篇 CentOS升级python3.9
由于最近在做智能机器人,需要python3.8的运行环境,才发现CentOS只附带了python2.7与python3.6,并且直接在终端运行python是无法找到目录的,说明python没有指定任何版本(缺少软链接)。这次尝试完美升级python3.9,自测成功。
检查python所有软链接
ls -al /usr/bin | grep python
安装依赖关系
yum -y install gcc python36-devel bzip2-devel sqlite-devel openssl-devel readline-devel xz-devel xz-devel tk-devel gdbm-devel libffi-devel
下载和安装python包
cd /usr/local/src
wget https://www.python.org/ftp/python/3.9.5/Python-3.9.5.tgz
若下载命令失效可尝试下列内容
cd /usr/local/src
wget https://pan.hanxucloud.cn/d/Onedrive/Alist/Applications/Linux/Python/Python-3.9.5.tgz
继续执行
tar zxvf Python-3.9.5.tgz
cd Python-3.9.5/
./configure --prefix=/usr/local/python3.9 --with-ssl
make && make install
修改软连接,使其可直接使用python激活python3.9,并且pip默认使用python3.9
ln -fs /usr/local/python3.9/bin/python3.9 /usr/bin/python
ln -fs /usr/local/python3.9/bin/python3.9 /usr/bin/python3
ln -fs /usr/local/python3.9/bin/pip3.9 /usr/bin/pip
ln -fs /usr/local/python3.9/bin/pip3.9 /usr/bin/pip3
修改yum文件,执行以下两个命令后弹出窗口的第一行改都修改为 #!/usr/bin/python2.7
(原因是安装了python3.8,CentOS 7.X 自带的yum采用的是python2.X,当系统将python升级到2.7 或3.X后,出现语法解释错误)
vi /usr/bin/yum
vi /usr/libexec/urlgrabber-ext-down
升级pip
python -m pip install --upgrade pip
再次检查python所有软链接,查看python命令是否成功指向了python3.9
ls -al /usr/bin | grep python
检查python安装目录
whereis python
若配置过程中出现错误必须:
ln -fs /usr/local/python3.9/bin/python3.9 /usr/bin/python
ln -fs /usr/local/python3.9/bin/python3.9 /usr/bin/python3
ln -fs /usr/local/python3.9/bin/pip3.9 /usr/bin/pip
ln -fs /usr/local/python3.9/bin/pip3.9 /usr/bin/pip3
来源:链接