欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

centos7 python升级python3.7

程序员文章站 2022-03-01 17:24:38
...

更新&&安装支撑

更新源&&包

#centos 7 添加阿里云镜像
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum install epel-release
#更新包
yum -y update

安装相关支撑

yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel libffi-devel
yum -y install gcc gcc-c++ kernel-devel

安装

下载解压

cd /usr/local
wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz
tar -xzvf Python-3.7.0.tgz

创建python3.7文件夹
配置安装路径&&编译

mkdir python3.7
cd Python-3.7.0 
./configure --prefix=/usr/local/python3.7
make && make install

更换系统默认的python和pip版本

备份系统旧的python版本
以备接下来yum依赖

mv /usr/bin/python /usr/bin/python2.7
mv /usr/bin/pip /usr/bin/pipold

建立指向新python3和pip3的软链接

ln -s /usr/local/python3/bin/python3.5 /usr/bin/python
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip

检查python和pip版本

python --version
pip --version

更新yum相关设置

因yum依赖python2,故修改文件

vim /usr/bin/yum

把第一行改了

#!/usr/bin/python—改成—> #!/usr/bin/python2.7

emmmm
用yum时可能又会出现另一种报错

Is this ok [y/d/N]: y
Downloading packages:
  File "/usr/libexec/urlgrabber-ext-down", line 28
    except OSError, e:
                  ^
SyntaxError: invalid syntax

解决方法

vim /usr/libexec/urlgrabber-ext-down

将第一行#!/usr/bin/python 改为 #!/usr/bin/python2.7即可

EeeeeeeeeeerroR


升级新版pip 之后,有可能是与旧版冲突出现的下面的错误

[[email protected] bin]# pip -V
Traceback (most recent call last):
  File "/usr/local/bin/pip", line 5, in <module>
    from pip._internal.cli.main import main
ModuleNotFoundError: No module named 'pip._internal.cli'

解决方法

 # 下载安装脚本
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
# 运行安装脚本
sudo python get-pip.py 

然后好了

[[email protected] bin]# pip --version
pip 20.0.2 from /usr/local/python3/lib/python3.7/site-packages/pip (python 3.7)


相关标签: # centos7 centos