CentOS下安装Python

Python: https://www.python.org/downloads/

安装

# wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz

# yum install gcc make libffi-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel
# tar -zxf Python-3.7.3.tgz 
# cd Python-3.7.3/
# ./configure --prefix=/usr/local/python37
# make
# make install

配置环境变量(python和pip)

# mv /usr/bin/python /usr/bin/python.bak
# ln -s /usr/local/python37/bin/python3 /usr/bin/python
# mv /usr/bin/pip /usr/bin/pip.bak
# ln -s /usr/local/python37/bin/pip3 /usr/bin/pip

验证

# python -V
Python 3.7.3
# pip -V
pip 19.0.3 from /usr/local/python37/lib/python3.7/site-packages/pip (python 3.7)

yum错误解决

更改系统默认的python命令后,再次使用yum命令报错:

# yum install openssl-devel
  File "/bin/yum", line 30
    except KeyboardInterrupt, e:
                            ^
SyntaxError: invalid syntax

这是因为yum采用python作为命令解释器,原来系统自带的python解释器为python2.7,而我们将python默认的解释器设为python3.7,导致按python3.7解析2.7的语法出错。

解决方法:

修改/usr/bin/yum/usr/libexec/urlgrabber-ext-down文件中的第一行为#!/usr/bin/python2.7

# vim /bin/yum

修改内容:

#!/usr/bin/python2.7
# vim /usr/libexec/urlgrabber-ext-down

修改内容:

#! /usr/bin/python2.7

版权声明:
作者:Joe.Ye
链接:https://www.appblog.cn/index.php/2023/02/26/install-python-under-centos/
来源:APP全栈技术分享
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
打赏
海报
CentOS下安装Python
Python: https://www.python.org/downloads/ 安装 # wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz # yum install gcc make libffi-devel……
<<上一篇
下一篇>>
文章目录
关闭
目 录