How do I replace python2 with py3 in my gnome terminal? Would
alias python='python3'
work? Thanks!
There is no need to replace Python. Use
python
for Python 2 and
python3
for Python 3 when calling your script.
As others have mentioned, changing python
to point to python3
system-wide could cause troubles and is probably not a good idea. However, if you only really want this behavior for a certain project, you could consider using pyenv to set what python
means within a particular directory. It's not in the repos, but it's relatively straightforward to set up following the github page. Once you have pyenv
installed and setup,
pyenv versions
will list the python versions you have installed. Then to set python
to point to the system's python3
only for the local directory (see doc), you can use
pyenv local 3.5.2
(assuming 16.04, or whatever python3
appears in the output of the pyenv versions
command).
Note, virtualenv
which is in the repos can also be used to similar effect. See a comparison here.
python3
? Do you really grudge that one keystroke? If you need to call python 2 you would have to dopython2.7
(two extra keystrokes)!python
symlink to point topython3
instead ofpython2
, then you also risk things going wrong because many programs and scripts assumepython
ispython2
. You can still have a Bash alias like @Zanna said, but my argument against this is it is doing more harm than good where the only good here is merely saving a single keystroke.chmod +x
'ed. The potential confusion here is that one might get too used to thinking thatpython
ispython3
and then get confused by a#!/usr/bin/env python
shebang, thinking that the Python 3 interpreter is being invoked when it is really still the Python 2 version of it that is invoked. By defining this alias, you now have to constantly remind yourselfpython
ispython3
only in your own interactive shells and not anywhere else.