Linux:阿里云centos7.3:安装和卸载python3.8.1,设置默认python 版本为python3

参考
https://www.jianshu.com/p/b809664d97e2
https://blog.csdn.net/elija940818/article/details/79238813
1、安装依赖包
sudo yum -y groupinstall "Development tools"

sudo 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 gcc gcc-c++ zlib zlib-devel libffi-devel gcc kernel-devel kenel-headers make bzip2
yum install libffi-devel -y
2、下载python
mkdir /usr/local/python3
cd /usr/local/python3
wget https://www.python.org/ftp/python/3.8.1/Python-3.8.1.tgz
3、解压安装
参考
https://blog.csdn.net/whatday/article/details/98053179

tar -zxvf Python-3.8.1.tgz
cd Python-3.8.1
./configure --prefix=/usr/local/bin/python3
sudo make && make install

#可选(目前安装失败,未解决)
./configure --prefix=/usr/local/bin/python3 --enable-shared  --enable-optimizations
参考
https://segmentfault.com/a/1190000019690270
https://blog.csdn.net/jxchallenger/article/details/95916906
https://wenku.baidu.com/view/29dfe13b4935eefdc8d376eeaeaad1f34693117d.html

# 把安装日志保存下来(可选)
make install > install.log

Linux:阿里云centos7.3:安装和卸载python3.8.1,设置默认python 版本为python3_第1张图片

4、创建软连接
ln -s /usr/local/bin/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/bin/python3/bin/pip3 /usr/bin/pip3

5、python配置
提示allow it anyway with '--trusted-host mirrors.aliyun.com'.
https://blog.csdn.net/weixin_43731793/article/details/104199697

6、更新pip
pip3 install --upgrade pip
python3.8安装flask出现错误“ModuleNotFoundError: No module named '_ctypes'”
https://www.cnblogs.com/ech2o/p/11752921.html
https://bugs.python.org/issue31652
https://www.e-learn.cn/content/wangluowenzhang/733100
https://stackoverflow.com/questions/16018463/difference-in-details-between-make-install-and-make-altinstall

卸载python3

参考
https://my.oschina.net/yysue/blog/1676411?spm=a2c6h.13066369.0.0.5fdb6db1qKUGFp
https://blog.csdn.net/qq_34244910/article/details/100146227
https://blog.csdn.net/SeaSky_Steven/article/details/88050487
删除文件
rm -rf

删除/usr/local/bin/python3
rm -rf /usr/local/bin/python3

删除/usr/bin软连接文件
rm -rf /usr/bin/python3
rm -rf /usr/bin/pip3

删除已解压的文件夹(可选)
rm -rf /usr/local/python3/Python-3.8.1

然后再次安装只需从解压开始即可。

设置默认python 版本为python3

参考
https://blog.csdn.net/qq_36464448/article/details/80373636

1、修改默认python

查看python的路径
ls -al /usr/bin | grep python
将原来python的软链接重命名
mv /usr/bin/python /usr/bin/python.bak
将 python 链接至 python3
ln -s /usr/local/bin/python3/bin/python3 /usr/bin/python
设置python2的pip为pip2
mv /usr/bin/pip /usr/bin/pip.bak
ln -s /usr/bin/pip2.7 /usr/bin/pip2

设置python3为pip
ln -s /usr/local/bin/python3/bin/pip3 /usr/bin/pip

2、配置yum和firewalld

vi /usr/bin/yum

将第一行”#!/usr/bin/python” 改为 “#!/usr/bin/python2.7”即可
vi /usr/libexec/urlgrabber-ext-down
修改”#!/usr/bin/python” 改为 “#!/usr/bin/python2.7
vi /usr/bin/firewall-cmd
首行的“python”都改为“python2.7
vi /usr/sbin/firewalld
首行的“python”都改为“python2.7

你可能感兴趣的:(python,Linux,linux,python)