Linux(ubuntu18.04)安装 python3,多版本管理与切换

ubuntu 18.04 自带 python 基础版本:python 2.7.17python 3.6.9

一、直接安装

```bash
# 下载
wget https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tgz
#########演示Python3.8.5安装#########
# 解压并进入源文件
tar -xzvf Python-3.8.5.tgz&&cd Python-3.8.5
# 配置和编译
./configure
# 编译安装(直接安装到 /usr 下面)
make -j16 && sudo make install
# 查看Python3的版本和路径:
python3 -V
which python3

二、自定义路径安装

# 下载
wget https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tgz
#########演示Python3.8.5安装#########
1、解压并进入源文件
tar -xzvf Python-3.8.5.tgz&&cd Python-3.8.5
2、配置和编译
./configure --prefix=/usr/local/python
make -j4
3、安装
sudo make install
4、查看扩展安装包:
/usr/local/python/bin/pip3 list
5、添加Python命令到环境变量:
sudo vim /etc/profile	或者 sudo vim ~/.bashrc
在最后增加一行:
export PATH=$PATH:/usr/local/python/bin
6、使环境变量生效:
source /etc/profile 或者 source ~/.bashrc
7、查看Python3的版本和路径:
python3 -V
which python3

三、更改系统默认python版本

# 更改系统默认python3版本为Python3.8
sudo rm /usr/bin/python3
sudo ln -s /usr/bin/python3.8 /usr/bin/python3

# 更改系统默认python版本为Python3.8
sudo rm /usr/bin/python
sudo ln -s /usr/bin/python3.8 /usr/bin/python

# 查看python当前默认版本
python -V

# 查看 python3 当前默认版本
python3 -V

# 查看所有安装的python路径
whereis python

# 查看所有安装的python3路径
whereis python3

python2.6.9安装

1、下载源文件
wget https://www.python.org/ftp/python/2.6.9/Python-2.6.9.tar.xz
2、解压并进入源文件
tar -xvf Python-2.6.9.tar.xz&&cd Python-2.6.9
3、配置和编译
./configure --prefix=/usr/local/python
make -j16
4、安装
sudo make install
5、更改系统默认python版本为Python2.6
sudo rm /usr/bin/python
sudo ln -s /usr/local/python/bin/python2.6 /usr/bin/python
6、查看python当前默认版本
python -V

Python3.8.0下载
Python3.8.5下载
Python3.9下载

  • 1
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值