dalaolala / blog

用issue来写博客 和别人学的
MIT License
71 stars 24 forks source link

centos7 升级到python3 #11

Open dalaolala opened 4 years ago

dalaolala commented 4 years ago

目前python2已经完全不更新了 而且会莫名其妙出现各种各样的问题

下面是升级到python3的方法

1、手动安装

curl -O https://www.python.org/ftp/python/3.5.0/Python-3.5.0.tgz

tar xf Python-3.5.0.tgz
cd Python-3.5.0
./configure
make
sudo make install

提示没有gcc,则要先安装一下

yum install gcc gcc-c++ -y

如果提示出现 'Ignoring ensurepip failure: pip 7.1.2 requires SSL/TLS'

yum install openssl-devel

2、使用一键脚本安装

bash <(curl -sL https://python3.netlify.com/install.sh)

参考这里:https://github.com/Jrohy/python3-install

dalaolala commented 2 years ago

安装pyhton3.7

1、下载安装包

https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz

3、配置安装环境

 #否则将会提示No module named‘_ctypes’
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
yum install -y libffi-devel zlib1g-dev
yum install zlib* -y
yum -y install gcc
yum -y groupinstall "Development tools"

4、编译安装python

tar xvf Python-3.7.0.tar 
cd Python-3.7.0
./configure --prefix=/usr/local/python3.7/ --enable-optimizations
make && make install

5、设置默认python

ln -s /usr/local/python3.7/bin/python3.7 /usr/bin/python3

ln -s /usr/local/python3.7/bin/pip3.7 /usr/bin/pip3

安装pyhton3.8

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

配置安装环境

 #否则将会提示No module named‘_ctypes’
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
yum install -y libffi-devel zlib1g-dev
yum install zlib* -y
yum -y install gcc
yum -y groupinstall "Development tools"

解压安装

# 解压压缩包
tar -zxvf Python-3.8.1.tgz  

# 进入文件夹
cd Python-3.8.1

# 配置安装位置
./configure prefix=/usr/local/python3

# 安装
make && make install

添加软链接

#添加python3的软链接 
ln -s /usr/local/python3/bin/python3.8 /usr/bin/python3 

#添加 pip3 的软链接 
ln -s /usr/local/python3/bin/pip3.8 /usr/bin/pip3
dalaolala commented 2 years ago

编译很慢解决办法

./configure --prefix=/usr/local/python3.7/
dalaolala commented 1 year ago

快速的安装python3.8版本

Centos 7 自带Python2.7.5版本。而默认的 YUM 安装的python3是 3.6版本,遂升级到3.8版本

# 仓库注册
yum install -y centos-release-scl 
# 安装python3.8
yum install -y rh-python38 which 

创建软链接

ln -s /opt/rh/rh-python38/root/usr/bin/python3 /usr/bin/python3
ln -s /opt/rh/rh-python38/root/usr/bin/pip3 /usr/bin/pip3