mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-26 21:30:55 +08:00
commit
06dc0237f2
@ -1,103 +0,0 @@
|
||||
Translating by Ping
|
||||
|
||||
How to change from default to alternative Python version on Debian Linux
|
||||
====================================================
|
||||
|
||||
Your Debian Linux installation may include multiple python versions and thus also include multiple python binary executables. You can run the following `ls` command to find out what python binary executables are available on your system:
|
||||
|
||||
```
|
||||
$ ls /usr/bin/python*
|
||||
/usr/bin/python /usr/bin/python2 /usr/bin/python2.7 /usr/bin/python3 /usr/bin/python3.4 /usr/bin/python3.4m /usr/bin/python3m
|
||||
```
|
||||
|
||||
To check what is your default python version execute:
|
||||
|
||||
```
|
||||
$ python --version
|
||||
Python 2.7.8
|
||||
```
|
||||
|
||||
1、Change python version on per user basis
|
||||
To change a python version on per user basis you simply create an `alias` within user's home directory. Open `~/.bashrc` file and add new alias to change your default python executable:
|
||||
|
||||
```
|
||||
alias python='/usr/bin/python3.4'
|
||||
```
|
||||
|
||||
Once you make the above change, re-login or source your `.bashrc` file:
|
||||
|
||||
|
||||
```
|
||||
$ . ~/.bashrc
|
||||
```
|
||||
|
||||
Check your default python version:
|
||||
|
||||
```
|
||||
$ python --version
|
||||
Python 3.4.2
|
||||
```
|
||||
|
||||
2、 Change python version system-wide
|
||||
To change python version system-wide we can use `update-alternatives` command. Logged in as a root user, first list all available python alternatives:
|
||||
|
||||
```
|
||||
# update-alternatives --list python
|
||||
update-alternatives: error: no alternatives for python
|
||||
```
|
||||
|
||||
The above error message means that no python alternatives has been recognized by `update-alternatives` command. For this reason we need to update our alternatives table and include both `python2.7` and `python3.4`:
|
||||
|
||||
```
|
||||
# update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
|
||||
update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in auto mode
|
||||
# update-alternatives --install /usr/bin/python python /usr/bin/python3.4 2
|
||||
update-alternatives: using /usr/bin/python3.4 to provide /usr/bin/python (python) in auto mode
|
||||
```
|
||||
|
||||
The `--install` option take multiple arguments from which it will be able to create a symbolic link. The last argument specified it priority means, if no manual alternative selection is made the alternative with the highest priority number will be set. In our case we have set a priority 2 for `/usr/bin/python3.4` and as a result the `/usr/bin/python3.4` was set as default python version automatically by `update-alternatives` command.
|
||||
|
||||
```
|
||||
# python --version
|
||||
Python 3.4.2
|
||||
```
|
||||
|
||||
Next, we can again list all python alternatives:
|
||||
|
||||
```
|
||||
# update-alternatives --list python
|
||||
/usr/bin/python2.7
|
||||
/usr/bin/python3.4
|
||||
```
|
||||
|
||||
From now on, we can anytime switch between the above listed python alternative versions using below command and entering a selection number:
|
||||
|
||||
```
|
||||
# update-alternatives --config python
|
||||
```
|
||||
|
||||
![](http://linuxconfig.org/images/change-python-alternative-version-debian-linux.png)
|
||||
|
||||
```
|
||||
# python --version
|
||||
Python 2.7.8
|
||||
```
|
||||
|
||||
3、 Appendix
|
||||
In case we no longer have the alternative python version installed on our system we can remove its `update-alternatives` listing. For example let's remove python2.7 version:
|
||||
|
||||
```
|
||||
# update-alternatives --remove python /usr/bin/python2.7
|
||||
update-alternatives: removing manually selected alternative - switching python to auto mode
|
||||
update-alternatives: using /usr/bin/python3.4 to provide /usr/bin/python (python) in auto mode
|
||||
```
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://linuxconfig.org/how-to-change-from-default-to-alternative-python-version-on-debian-linux
|
||||
|
||||
作者:[作者][]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
@ -0,0 +1,104 @@
|
||||
如何将 Debian Linux 系统中默认的 Python 替代为其他版本
|
||||
====================================================
|
||||
|
||||
当你安装 Debian Linux 时,安装过程有可能同时为你提供多个可用的 Python 版本,因此系统中会存在多个 Python 的可执行二进制文件。你可以按照以下方法使用 `ls` 命令来查看你的系统中都有那些 Python 的二进制文件可供使用。
|
||||
|
||||
```
|
||||
$ ls /usr/bin/python*
|
||||
/usr/bin/python /usr/bin/python2 /usr/bin/python2.7 /usr/bin/python3 /usr/bin/python3.4 /usr/bin/python3.4m /usr/bin/python3m
|
||||
```
|
||||
|
||||
执行如下命令查看默认的 Python 版本信息:
|
||||
|
||||
```
|
||||
$ python --version
|
||||
Python 2.7.8
|
||||
```
|
||||
|
||||
1、基于用户修改 Python 版本:
|
||||
|
||||
想要为某个特定用户修改 Python 版本,只需要在其 home 目录下创建一个 `alias(别名)` 即可。打开 `~/.bashrc` 文件,添加新的别名信息来修改默认使用的 Python 版本。
|
||||
|
||||
```
|
||||
alias python='/usr/bin/python3.4'
|
||||
```
|
||||
|
||||
一旦完成以上操作,重新登录或者重新加载 `.bashrc` 文件,使操作生效。
|
||||
|
||||
```
|
||||
$ . ~/.bashrc
|
||||
```
|
||||
|
||||
检查当前的 Python 版本。
|
||||
|
||||
```
|
||||
$ python --version
|
||||
Python 3.4.2
|
||||
```
|
||||
|
||||
2、 基于系统级别修改 Python 版本
|
||||
|
||||
我们可以使用 `update-alternatives` 来为整个系统更改 Python 版本。以 root 身份登录,首先罗列出所有可用的 python 替代版本信息:
|
||||
|
||||
```
|
||||
# update-alternatives --list python
|
||||
update-alternatives: error: no alternatives for python
|
||||
```
|
||||
|
||||
如果出现以上所示的错误信息,则表示 Python 的替代版本尚未被 `update-alternatives` 命令识别。想解决这个问题,我们需要更新一下替代表,将 `python2.7` 和 `python3.4` 放入其中。
|
||||
|
||||
```
|
||||
# update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
|
||||
update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in auto mode
|
||||
# update-alternatives --install /usr/bin/python python /usr/bin/python3.4 2
|
||||
update-alternatives: using /usr/bin/python3.4 to provide /usr/bin/python (python) in auto mode
|
||||
```
|
||||
|
||||
`--install` 选项使用了多个参数用于创建符号链接。最后一个参数指定了此选项的优先级,如果我们没有手动来设置替代选项,那么具有最高优先级的选项就会被选中。这个例子中,我们为 `/usr/bin/python3.4` 设置的优先级为2,所以 `update-alternatives` 命令会自动将它设置为默认 Python 版本。
|
||||
|
||||
```
|
||||
# python --version
|
||||
Python 3.4.2
|
||||
```
|
||||
|
||||
接下来,我们继续列出可用的 Python 替代版本。
|
||||
|
||||
```
|
||||
# update-alternatives --list python
|
||||
/usr/bin/python2.7
|
||||
/usr/bin/python3.4
|
||||
```
|
||||
|
||||
现在开始,我们就可以使用下方的命令随时在列出的 Python 替代版本中任意切换了。
|
||||
|
||||
```
|
||||
# update-alternatives --config python
|
||||
```
|
||||
|
||||
![](http://linuxconfig.org/images/change-python-alternative-version-debian-linux.png)
|
||||
|
||||
```
|
||||
# python --version
|
||||
Python 2.7.8
|
||||
```
|
||||
|
||||
3、附录
|
||||
|
||||
一旦我们的系统中不再存在某个 Python 的替代版本时,我们可以将其从 `update-alternatives` 列表中删除掉。例如,我们可以将列表中的 python2.7 版本移除掉。
|
||||
|
||||
```
|
||||
# update-alternatives --remove python /usr/bin/python2.7
|
||||
update-alternatives: removing manually selected alternative - switching python to auto mode
|
||||
update-alternatives: using /usr/bin/python3.4 to provide /usr/bin/python (python) in auto mode
|
||||
```
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://linuxconfig.org/how-to-change-from-default-to-alternative-python-version-on-debian-linux
|
||||
|
||||
作者:[作者][]
|
||||
译者:[mr-ping](https://github.com/mr-ping)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
Loading…
Reference in New Issue
Block a user