linux 下介绍python3.8安装

linux 下介绍python3.8安装

首先先确认下是否有安装wget,如果没有安装请先安装wget
[php]
yum -y install wget
[/php]
安装好后下载python3.8
[php]wget https://www.python.org/ftp/python/3.8.11/Python-3.8.11.tgz[/php]

下载好后在你喜欢的目录下创建目录
我是安装到/usr/local/python3.8,创建目录
[php]mkdir -p /usr/local/python3.8[/php]

创建好后将文件移动到/usr/local/python3.8目录下,解压该文件
[php]tar -zxvf Python-3.8.11.tgz[/php]

进入解压后的目录,编译安装
[php]./configure –prefix=/usr/local/python3.8[/php]

编译:make
编译成功后,编译安装:make install

vi /etc/profile
在最下边输入
[php]
export PYTHON_HOME=/usr/local/python3.8
export PATH=${PYTHON_HOME}/bin:$PATH
[/php]
使得配置的环境变量立即生效
[php]source /etc/profile[/php]

安装好后想使用python命令运行脚本
将 python 各版本添加到 update-alternatives
[php]
which python3.8
sudo update-alternatives –install /usr/bin/python python /usr/bin/python 1
sudo update-alternatives –install /usr/bin/python python /usr/bin/python3.6 2
sudo update-alternatives –install /usr/bin/python python /usr/local/python3/python3.8/bin/python3 3
[/php]

配置 python 默认指向 python3.8
[php]sudo update-alternatives –config python[/php]

Python 却换版本
采用软链接的方式却换
[php]
whereis python
rm /usr/bin/python
ln -s /usr/local/python/bin/python3.8 /usr/bin/python
[/php]

发表评论

© 2022. powered by PHP 个人小站