How do I switch from python 2.6 to 2.7 by default

2019-10-03 15:49发布

How do I switch from python 2.6 to 2.7 by default

ls -l /usr/bin/python*
lrwxrwxrwx 1 root root    9 Jan 27 12:36 /usr/bin/python -> python2.6
lrwxrwxrwx 1 root root    9 Jan 27 12:36 /usr/bin/python2 -> python2.6
-rwxr-xr-x 2 root root 3664 Sep 13 00:25 /usr/bin/python26
-rwxr-xr-x 2 root root 3664 Sep 13 00:25 /usr/bin/python2.6
-rwxr-xr-x 1 root root 1418 Sep 13 00:25 /usr/bin/python2.6-config
-rwxr-xr-x 2 root root 3664 Nov 12 02:03 /usr/bin/python27
-rwxr-xr-x 2 root root 3664 Nov 12 02:03 /usr/bin/python2.7
lrwxrwxrwx 1 root root   22 Sep  1 09:52 /usr/bin/python3 -> /usr/local/bin/python3
lrwxrwxrwx 1 root root   16 Jan 27 12:36 /usr/bin/python-config -> python2.6-config
lrwxrwxrwx 1 root root   16 Jan 27 12:36 /usr/bin/python-config2 -> python2.6-config

2条回答
够拽才男人
2楼-- · 2019-10-03 16:07

A lot of Ubuntu packages use python. They also install modules in /usr/lib/pythonX.Y where (X.Y is your default python version).

The python packaging system only provides those modules for the default python.

If you change your default python, it would become your responsibility to provide those modules for the new version of python or else your system will break.

Therefore, unless you really know what you are doing (i.e. you are willing to port and maintain all those modules), I would strongly recommend not trying to change the default version of python.

Instead use virtualenv and virtualenvwrapper to allow you to switch versions at the user level.

查看更多
成全新的幸福
3楼-- · 2019-10-03 16:07

Create a folder in your home folder like .bin (or whatever you want)

Open your terminal configuration file (.bashrc , .zshrc ..) and modify your $PATH variable. like

export PATH=$HOME/.bin:$PATH

then put a symlink to there.

ln -s /usr/bin/python2.7 ~/.bin/python
ln -s /usr/bin/python2.7-config ~/.bin/python-config

with this way you don't have to change something systemwide.

otherwise you can change the global symlinks to change them system wide. But i can affect sth. you don't know.

The first method will be more stable & secure.

查看更多
登录 后发表回答