Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have python3.2 located in /usr/lib/python3.2. I am not sure if that means it's installed but I assume it is for now.

Some facts about my system:

$ which python
/usr/local/bin/python

When I type python in terminal I get the following

$ python
Python 2.7.2 (default, Dec 19 2011, 11:12:13) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.

Then to find the path I do

>>> sys.info
>>> sys.path
['', '/usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg', '/usr/local/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg', '/usr/local/lib/python2.7/site-packages/PIL-1.1.7-py2.7-linux-x86_64.egg', '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7', '/usr/local/lib/python2.7/plat-linux2', '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old', '/usr/local/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/site-packages']

So knowing all of this, how do I change my default system python from 2.7.2 to 3.2?

share|improve this question

6 Answers 6

up vote 8 down vote accepted

It's not good to change the default python. Many system programs depends on python2 not python3. if you want to use python3, you just type the command python3.

share|improve this answer
    
For support libraries and tools (like pyenv, fabric), they expect /usr/bin/env python to be what you want. So manually typing python3 isn't the solution. –  Konklone Jul 22 at 16:07

The PYTHONPATH doesn't have much to do with it. It just tells the Python interpreter, whichever interpreter runs, where to find extra modules you want to load.

But either way, changing the default version on your system is dangerous, as other commenters have observed. You stand the risk of breaking existing package that are built against Python2 and use /usr/bin/env python to find their interpreters.

In fact, that's the wrong way to phrase it. Changing the default version of Python will break your entire Ubuntu system and cause lots of programs to just not work. It's also completely unnecessary.

But since you asked, you just do this:

sudo rm /usr/bin/python
sudo ln -s /usr/bin/python3.2mu /usr/bin/python

Happy crashing!

share|improve this answer

According to this you can setup your enviroment variable or just add new import path folder. But I recommend to use virtualenvs for python projects if you will want to have some flexibility.

share|improve this answer

I added this in my .bashrc, its working fine so far:

alias python='python3'
share|improve this answer

if it is in fact installed type in python3.2 instead of just python and it will load that instead of the default. Just installed python 3.2 to test it out =)

if it is not in fact installed open terminal and type sudo apt-get install python3.2 to get it

share|improve this answer

Here is the safest way to do this - using update-alternatives

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.