centos (linux) 安装python 3
1、查看python安装目录whereis python2、查看/usr/bin/目录下的python文件ls -al /usr/bin/python*3、安装python3相关的安装包,用于编译python3yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-d
·
1、查看python安装目录
whereis python
2、查看/usr/bin/目录下的python文件
ls -al /usr/bin/python*
3、安装python3相关的安装包,用于编译python3
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make -y
安装完成后的截图:
3.1、如果出现安装失败,提示找不到源,可以通过更换yum源解决,更新为阿里源。
3.1.1、修改yum源的文件
vi /etc/yum.repos.d/CentOS-Base.repo
3.1.2、把内容替换成阿里源的网址
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/$releasever/os/$basearch/
https://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
https://mirrors.aliyun.com/centos$releasever/os/$basearch/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
https://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
https://mirrors.aliyun.com/centos$releasever/updates/$basearch/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
https://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
https://mirrors.aliyun.com/centos$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
https://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
https://mirrors.aliyun.com/centos$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
https://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
https://mirrors.aliyun.com/centos$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
3.1.3、清理源缓存
yum clean all
3.1.4、更新源缓存
yum makecache
3.1.5、再次执行安装命令
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make -y
4、安装pip
yum install python-pip -y
5、下载python3
写这个文档是,python最新版本是3.9.4版本,所以我安装的是3.9.4版本
wget https://www.python.org/ftp/python/3.9.4/Python-3.9.4.tar.xz
6、把python安装包移动到/home/tool目录
tool目录是我自己创建的目录,用途就是放置python3的安装包。
mv Python-3.9.4.tar.xz /home/tool/
7、解压python安装包
tar -xf Python-3.9.4.tar.xz
8、进入解压后的python目录
cd ./Python-3.9.4/
9、编译python3
./configure prefix=/usr/local/python3
10、在python3.9.4目录里,安装python3
make && make install
12、查看/usr/local/目录下是否有python3的文件,有则证明安装成功
ls -al /usr/local/
11、将之前的python软连接备份
mv /usr/bin/python /usr/bin/python.bak
12、添加新的软连接,把python3的软连接添加到python文件里
ln -s /usr/local/python3/bin/python3.9 /usr/bin/python
13、查看python版本号
python -V
更多推荐
已为社区贡献1条内容
所有评论(0)