目录

对于小白教友好的ubuntu18.04中更改默认python版本方法

对于小白教友好的ubuntu18.04中更改默认python版本方法

**

对于小白教友好的ubuntu18.04中更改默认python版本方法

注:Ubuntu18.04自带了python3

**

在我新安装的ubuntu18.04版本中是没有默认的python版本的 在终端输入python显示如下:

https://i-blog.csdnimg.cn/blog_migrate/dc46121d76b553e400d5b0e15344dfe6.png

表示你有python3 可以运行python3,但是只能这样运行:

https://i-blog.csdnimg.cn/blog_migrate/b18207d82ba5f7c24f8f66d3e9afba46.png

在这种情况下就需要我们自身添加默认版本了,在网上一般是两种方式添加,我选择其中一种介绍,给我的感觉这种方式对于小白来说更加友好。

话不多说 ,教程如下:

1 查看python版本

ls /usr/bin/python*

https://i-blog.csdnimg.cn/blog_migrate/d0d9a35391c296e1a2aaad0d0892c399.png

我的自带python3和python3.6的版本

2 查看python版本路径

1 which python3
2 which python3.6

https://i-blog.csdnimg.cn/blog_migrate/3ded7748562459eaba29cc3f7f1731d9.png

3 建立链接 (使用 update-alternatives –install –·········语句)

1 sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 1
2 sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 2

https://i-blog.csdnimg.cn/blog_migrate/c29e59c278384c1b154bc9aa59fb98aa.png

即我们在/usr/bin/python这个目录下,建立一个链接符号为“Python”的链接,这里指定了两个目录,分别是Python3.6和Python3.7的.用优先级1和2 来表示优先级。

4 选择要执行的版本

sudo update-alternatives --config python

https://i-blog.csdnimg.cn/blog_migrate/d87fc7709ad58593ef687b801cbf817b.png

这里我们直接回车就ok了

5 查看效果

https://i-blog.csdnimg.cn/blog_migrate/4ad86b3da821eb81399ef7b71cae665d.png

ok 这里我们python默认版本就设置好了,这里我选择的是python3.6版本。