3

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.

8
  • 4
    What version of Linux are you using? The only distribution that symlinks python to python3 is Arch AFAIK. Commented Sep 23, 2013 at 11:24
  • 1
    How did you install the module? python3.3 setup.py install should do the right thing, if you installed from source. Commented Sep 23, 2013 at 11:30
  • @Wooble python3.3 setup.py install It is failing with errors. Module is pexpect-2.3. Commented Sep 23, 2013 at 11:35
  • 1
    "Pexpect was written and tested with Python 2.5. It should work on earlier versions that have the pty module." would make me think there's no way it's going to run on Python 3. Commented Sep 23, 2013 at 11:40
  • 1
    pexpect-u looks like a fork that does work on python 3; haven't tried it myself. Commented Sep 23, 2013 at 11:42

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

1 Comment

Note that there is a reason why those distribution use python2 as reference for the python executable: some programs are still not python3 ready. While (e.g.) Ubuntu is putting a hardwork moving towards python3, it still has to update quite some of its components which means that doing what you describe will currently break a lot of your system. Hopefully in one or two years the major distributions will move to python3 only, but until then I don't think this is a good idea. Just specify python3 when launching your programs!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.