The python program command executes Python 2. Python 3 can be executed using the python3 command. How can Python 3 be executed using the python command?
|
|
A simple safe way would be to use an alias. Place this into
After adding the above in the file. run the below command
example:
|
|||||||||||||||||||||
|
|
[June 2016] The recommended place for information on the transition is official Ubuntu Python page. From the Ubuntu wiki:
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 Such as:
or
Scripts can then start with something like:
instead of
I would still recommend using Using |
|||||||||||||||||||||
|
Update: This is the wrong way, I have learned, since Python2 and Python3 are not interchangeable.You can try the command line tool
If you get the error "no alternatives for python" then set up an alternative yourself with the following command:
Change the path |
|||||||||||||
|
|
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. |
|||
|
|
|
Do
then write either
or
Save the file, close the terminal and open it again. |
|||
|
|
|
You can use 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 |
|||||||||
|
(provided you have write permission to /usr/local/bin) likewise
then you only type py (and use py in #! lines) for your chosen python. |
|||
|
|
protected by heemayl Mar 25 '16 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 (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?