更改Ubuntu 默认Python版本

环境

  • ubuntu-16.04.4-desktop-amd64

更换方法

查看默认的 Python 版本信息

查看系统存在的Python版本

ls /usr/bin/python*

查看系统默认的Python版本

$ python --version

基于用户修改 Python 版本

为某个特定用户修改Python版本,只需要在其home目录下创建一个alias(别名) 即可。
打开该用户的~/.bashrc文件,添加新的别名信息来修改默认使用的 Python 版本。

alias python='/usr/bin/python3.4'

重新登录或者重新加载.bashrc文件,使操作生效

$ . ~/.bashrc

检查当前的Python版本

$ python --version

在系统级修改 Python 版本

使用update-alternatives来为整个系统更改 Python 版本。
以 root 身份登录,首先罗列出所有可用的 python 替代版本信息:

update-alternatives --list python

update-alternatives: error: no alternatives for python

如果出现以上所示的错误信息,则表示 Python的替代版本尚未被update-alternatives 命令识别。
需要更新一下替代列表,将python2.7和python3.5放入其中。

update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2

--install 选项使用了多个参数用于创建符号链接。
最后一个参数指定了此选项的优先级,如果我们没有手动来设置替代选项,那么具有最高优先级的选项就会被选中。

查看系统当前的Python版本

python --version

查看可用的 Python 替代版本

update-alternatives --list python

移除替代版本

一旦系统中不再存在某个Python的替代版本时,可以将其从 update-alternatives 列表中删除掉。

update-alternatives --remove python /usr/bin/python2.7

4
down vote
I solved the problem. At first I noticed that there is no problem if i call python -m pip. Then i removed a file named pip under /usr/local/bin (I don’t know why it was there), now everything is working as expected.

系统使用的pip2.7的部分

安装setuptools怎么安装

二、ubuntu平台下安装python-pip和python-setuptools

方式1:利用Ubuntu软件中心或者新立德包管理软件搜索python-pip和python-setuptools直接安装

方式2:利用bash,输入shell指令

sudo apt-get install python-pip
sudo apt-get install python-setuptools

版本的匹配

对于Python 需要3.4、3.5,部分需要2.7
对于pip 需要2.7

对于Python的版本 Fuck!!!

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值