更换ubuntu的python版本
时间: 2023-09-25 09:06:19 浏览: 95
如果你想更换Ubuntu系统默认的Python版本,可以按照以下步骤:
1. 确认系统已经安装了要更换的Python版本,比如Python 3.7。可以使用以下命令安装:
```
sudo apt-get update
sudo apt-get install python3.7
```
2. 安装并使用update-alternatives工具,该工具可以更新系统中的软链接,使其指向新安装的Python版本。使用以下命令安装:
```
sudo apt-get install update-alternatives
```
3. 添加新的Python版本到update-alternatives中,使用以下命令:
```
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.7 1
```
其中,`/usr/bin/python3.7`是新安装的Python版本的路径,数字1表示优先级(如果有多个版本,可以根据需要设置不同的优先级)。
4. 使用update-alternatives选择新的Python版本作为系统默认版本,使用以下命令:
```
sudo update-alternatives --config python
```
会出现以下类似提示,选择你要使用的版本即可:
```
There are 2 choices for the alternative python (providing /usr/bin/python).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/bin/python2.7 2 auto mode
* 1 /usr/bin/python3.7 1 manual mode
2 /usr/bin/python3.8 2 manual mode
Press <enter> to keep the current choice[*], or type selection number:
```
5. 验证新的Python版本是否生效,使用以下命令:
```
python --version
```
如果输出的版本号是你刚刚选择的新版本,说明更换成功了。
阅读全文
相关推荐















