Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I can access Python 3 via python3 command. But I want to make the default interpreter to use python command for Python 3. Simple typing python takes me to Python 2. How to upgrade?

share|improve this question
up vote 62 down vote accepted

A simple safety way would be to use an alias, by placing:

alias python=python3

into ~/.bashrc or ~/.bash_aliases file.

share|improve this answer

From the Ubuntu wiki:

For both Ubuntu and Debian, we have ongoing project goals to make Python 3 the default, preferred Python version in the distros.

What this does not mean:

  • /usr/bin/python will point to Python 3. No, this is not going to happen (unless PEP 394 advocates otherwise, which is doubtful for the foreseeable future). /usr/bin/python and /usr/bin/python2 will point to Python 2.7 and /usr/bin/python3 will point to the latest supported Python 3 version.

  • Python 2 will be removed from the archive. No, this is not going to happen. We expect Python 2.7 to remain supported and available in Ubuntu for quite a long time, given that PEP 373 promises upstream bug fix maintenance support until 2020.

It is not recommended to change the symbolic link because of other package dependencies, but they "have ongoing project goals to make Python 3 the default, preferred Python version in the distros".


For CLI use, like @Radu Rădeanu, I would recommend putting an alias in the user's ~/.bashrc, .bash_aliases file (the different files, including ~/.bash_profile, are all loaded together and are simply for organizational purposes).

Such as:

alias python=python3

or

alias python='/usr/bin/python3'

Scripts can then start with something like:

#!/usr/bin/env python

instead of

#!/usr/bin/python3

I would still recommend using #!/usr/bin/python3 in scripts for simpler cross-compatibility.

share|improve this answer

Or simply, you just create a symbolic link to python3.4 in /usr/bin (of course, you should delete old symbolic link):

sudo ln -s /usr/bin/python3.4 /usr/bin/python
share|improve this answer
cat > /usr/local/bin/py
#!/usr/bin/dash
python3 "$@"
<CTRL-D>

(provided you have write permission to /usr/local/bin) likewise

cat > /usr/local/bin/pyi
#!/usr/bin/dash
python3 -i "$@"
<CTRL-D>

then you only type py (and use py in #! lines) for your chosen python.

share|improve this answer

Ubuntu, and the rest of the Linux distros for that matter, are still largely dependent on Python 2.7 for a number of applications and commands. If you change the default reference of "python" to Python 3.x, then a number of Python functions will start throwing assertion errors.

For example, on Ubuntu, 'pip' for one would no longer run correctly unless you directly edited the file and changed the shebang to reference '#!/usr/bin/env python2.7'. On RHEL (Red Hat Enterprise Linux) flavors such as Red Hat, Fedora and CentOS, the 'Yum' command is also dependent on Python 2.7.

My point here is that you would cause a significant amount of code to start throwing assertion errors just so you could type 'python' in the terminal to reference Python 3.x.

You're much better off with using the 'python3' command in the terminal and the shebang '#!/usr/bin/env python3' in your Python 3.x files.

share|improve this answer

You can use update-alternatives to provide different versions of programs that may be needed at different times due to compatibility issues.

This answer Is a good example for how to set things up for simultaneously maintaining different versions of gcc/g++, for example.

just do the same with python2.7 and python 3.3

share|improve this answer

[Update: This is the wrong way, I have learned, since Python-2 and Python-3 are not really interchangeable.]

You can try the command line tool update-alternatives.

$ sudo update-alternatives --config python

If you get the error "no alternatives for python" then set up an alternative yourself with the following command:

$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10

Change the path /usr/bin/python3 to your desired python version accordingly.

share|improve this answer

protected by heemayl Mar 25 at 17:01

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.
{"cc_re__cc_re__cc_by_sa_3_0": ["                    <li><a href=\"//area51.stackexchange.com\" title=\"proposing new sites in the Stack Exchange network\">Area 51</a></li>\r\n                        <li><a href=\"//careers.stackoverflow.com\">Stack Overflow Careers</a></li>\r\n                    \r\n                </ol>\r\n            </td>\r\n    </tr>\r\n</table>\r\n                </div>\r\n            </div>\r\n            <div id=\"copyright\">\r\n                site design / logo &#169; 2016 Stack Exchange Inc; user contributions licensed under <a href=\"https://creativecommons.org/licenses/by-sa/3.0/\" rel=\"license\">cc by-sa 3.0</a> \r\n                with <a href=\"http://blog.stackoverflow.com/2009/06/attribution-required/\" rel=\"license\">attribution required</a>\r\n            </div>\r\n            <div id=\"svnrev\">\r\n                rev 2016.5.4.3543\r\n            </div>\r\n                <div id=\"additional-notices\">\r\n                    Ubuntu and Canonical are registered trademarks of Canonical Ltd.\r\n                </div>\r\n        </div>\r\n    </div>\r\n    <noscript>\r\n        <div id=\"noscript-warning\">Ask Ubun"], "copyright__copyright__copyright": ["in/python3 10\n\nChange the path /usr/bin/python3 to your desired python version accordingly.\n\nshare|improve this answer\n\nprotected by heemayl Mar 25 at 17:01\n\nThank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site.\n\nWould you like to answer one of these unanswered questions instead?\n\nNot the answer you're looking for? Browse other questions tagged or ask your own question."]}