问题
I want to upgrade python's default version i.e /usr/bin/python
in Linux.
I have multiple python versions installed as
/usr/bin/python2.7
/usr/bin/python3.3
However, python
command still returns python2.7
# python
Python 2.7
Type "help", "copyright", "credits" or "license" for more information.
>>>
Now, I have installed a module, which got installed in the default version 2.7
.
That's why I can't use python3.3 script.py
, as it returns error for missing module.
How to update this default version to 3.3
?
Is there a way to install the module in /usr/bin/python3.3
as well?
Added: Module is pexpect-2.3
.
回答1:
Installing new python
, installs by default in /usr/local/bin
.
Adding this path to PATH before previous default python's path, solves the problem.
export PATH=/usr/local/bin:$PATH
# This export statement could be added to .bashrc for permanent effect.
This way old python is not messed and new one is installed.
Also, If there is already a python
present in /usr/local/bin
, changing symbolic link of /usr/local/bin/python
to new /usr/local/bin/python3.3
solves the problem. (Python install generally only creates link when it installs in /usr/local/bin. You can do ls
on /usr/local/bin/python to verify that it is link. Because python is installed as /usr/local/bin/python2.7 and then a link to this is created as below)
/usr/local/bin/python -> /usr/local/bin/python2.7
or
/usr/local/bin/python -> /usr/local/bin/python3.3
Ofcourse, path of this should be added to PATH as already mentioned above.
It's always better to never touch and mess with /usr/bin/python
version, unless there is strong reason, because /usr/bin/python is generally not a link and is required by many of os modules.
回答2:
The accepted answer is good though, however I have found another hack trick to this problem and I think it's pretty simple.
At the location of /usr/bin/
there are many python related files available. You can see the file python
is actually a link and it points to the python2
(which is pointed to python2.7
).
So whenever you command python it calls the python2.7
not python3.5
The solution is to delete the original python
link and make another link that points to python3.5
and make the newly link file name to python
.
And you are done. :D
来源:https://stackoverflow.com/questions/18957836/upgrading-default-python-version-or-install-another-python-version-in-linux