0


ubuntu修改默认python为python3

1 ubuntu默认python

ubuntu 大多镜像版本都会携带python解释器:

  • ubuntu16.04 python指令进入python2.7,默认python3.5 如果没有python我们需要自己安装,ubuntu16.04安装python需要下载源码编译安装: python下载地址 选择心仪的python版本:
tar -zxvf Python-3.6.9.tgz
cd Python-3.6.9
./configure
make&&makeinstall
  • ubuntu18.04 python指令进入python2.7,默认python3.6.9 18.04系统安装python相对简单了
sudoapt-get update
sudoapt-getinstall python2.7 -y     # 安装python2.7sudoapt-getinstall python-pip -y     # 安装python下载库pip工具sudoapt-getinstall python3.6 -y      # 安装python3.6sudoapt-getinstall python3-pip -y # 安装python3下载库pip3工具

2 修改默认python脚本

(1)查看python可执行文件位置

➜  bin whereis python   
python: /usr/bin/python3.5m /usr/bin/python3.5 /usr/lib/python2.7 /usr/lib/python3.5 /etc/python3.5 /usr/local/bin/python3.6 /usr/local/bin/python3.6m-config /usr/local/bin/python3.6m /usr/local/bin/python3.6-config /usr/local/lib/python3.6 /usr/local/lib/python3.5

(2)我的python3.6可执行文件在/usr/local/bin/python3.6,我们只需要将/usr/bin/python删掉,创建指向python3.6的软连接即可:

➜  /usr sudorm /usr/bin/python
➜  /usr sudoln -s /usr/local/bin/python3.6 /usr/bin/python

(3)终端执行python指令

➜  /usr python
Python 3.6.9 (default, Oct 142022, 11:19:55)[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license"formore information.
>>>

没有问题,大功告成

标签: python ubuntu linux

本文转载自: https://blog.csdn.net/weixin_45805339/article/details/127319233
版权归原作者 阳光_你好 所有, 如有侵权,请联系我们删除。

“ubuntu修改默认python为python3”的评论:

还没有评论