user966588
user966588

Reputation:

upgrading default python version or install another python version in Linux

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.

Upvotes: 3

Views: 18302

Answers (2)

Shiba Prasad J.
Shiba Prasad J.

Reputation: 387

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

Upvotes: 1

user966588
user966588

Reputation:

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.

Upvotes: 1

Related Questions