CentOS 7 安装 python3

Posted whale-hunter

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS 7 安装 python3相关的知识,希望对你有一定的参考价值。

步骤详情

1、CentOS安装Python的依赖包

yum groupinstall "Development tools" yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel . .

2、下载Python3X的源码包并编译

wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz tar -zxvf Python-3.6.1.tgz cd Python-3.6.1 ./configure --prefix=/usr/local/python36 yum -y install zlib* openssl-devel make && make install . .

3、把#! /usr/bin/python修改为#! /usr/bin/python2

sed -i ‘s/#!/usr/bin/python/#!/usr/bin/python2.6/‘ /usr/bin/yum (可选)sed -i ‘s/#! /usr/bin/python/#! /usr/bin/python2/‘ /usr/libexec/urlgrabber-ext-down . .

4、把/usr/bin/下的python2替换成python3

mv /usr/bin/python /usr/bin/pythonold cp /usr/local/python36/bin/python3.6 /usr/bin/python cp /usr/local/python36/bin/pip3 /usr/bin/pip3 . .

写成shell脚本执行



#1、CentOS安装Python的依赖包 yum groupinstall "Development tools" yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel #2、下载Python3X的源码包并编译 wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz tar -zxvf Python-3.6.1.tgz cd Python-3.6.1 ./configure --prefix=/usr/local/python36 yum -y install zlib* openssl-devel make && make install #3、把 /usr/bin/yum 文件头中的 #! /usr/bin/python修改为#! /usr/bin/python2 不一定是这个名字,反正 yum 文件头要指定一个 python2的文件,可以是python2.7 sed -i ‘s/#!/usr/bin/python/#!/usr/bin/python2.6/‘ /usr/bin/yum #(可选)sed -i ‘s/#! /usr/bin/python/#! /usr/bin/python2/‘ /usr/libexec/urlgrabber-ext-down #4、把/usr/bin/下的python2替换成python3 mv /usr/bin/python /usr/bin/pythonold cp /usr/local/python36/bin/python3.6 /usr/bin/python cp /usr/local/python36/bin/pip3 /usr/bin/pip3

以上是关于CentOS 7 安装 python3的主要内容,如果未能解决你的问题,请参考以下文章

CentOS 7.5 安装 Python3.7

CentOS 7 安装python3.6.1

CentOS7安装Python3.7

CentOS 7 安装python3

CentOS 7安装Python3

centos7下安装python3.7