debian用户指定Python版本

创建命令alias

安装好debian后系统可能会自带多个python版本,在不改变系统默认设置的前提下我们可以给当前用户通过建alias的方式指定python版本

  • 查看当前系统已有的Python版本
dqeric@debian:~$ ll /usr/bin/python*
lrwxrwxrwx 1 root root       9 1月  24  2017 /usr/bin/python -> python2.7
lrwxrwxrwx 1 root root       9 1月  24  2017 /usr/bin/python2 -> python2.7
-rwxr-xr-x 1 root root 3779512 11月 25  2017 /usr/bin/python2.7
lrwxrwxrwx 1 root root       9 1月  20  2017 /usr/bin/python3 -> python3.5
-rwxr-xr-x 2 root root 4747120 1月  19  2017 /usr/bin/python3.5
-rwxr-xr-x 2 root root 4747120 1月  19  2017 /usr/bin/python3.5m
lrwxrwxrwx 1 root root      10 1月  20  2017 /usr/bin/python3m -> python3.5m
  • 查看默认版本
dqeric@debian:~$ python
Python 2.7.13 (default, Nov 24 2017, 17:33:09) 
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 
  • 查看当前用户配置文件
dqeric@debian:~$ cat .bashrc 

可以看到下面配置, 这个就是放alias的单独配置文件

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi
  • 新建或在已有文件中添加配置后为
dqeric@debian:~$ cat .bash_aliases 
# add alias
alias python='/usr/bin/python3.5'
  • 激活配置后测试Python版本
dqeric@debian:~$ . ~/.bashrc 
dqeric@debian:~$ python
Python 3.5.3 (default, Jan 19 2017, 14:11:04) 
[GCC 6.3.0 20170118] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值