How do I replace python2 with py3 in my gnome terminal? Would
alias python='python3'
work? Thanks!
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)! – Zanna Sep 13 '16 at 11:18python3– Zanna Sep 13 '16 at 11:333but gained 3 adding2.7– Zanna Sep 13 '16 at 11:56python2.7, there is also justpython2. – Byte Commander Sep 13 '16 at 12:29readlink $(which python)to go one level and I get2.7– Zanna Sep 13 '16 at 12:36python2pointing topython2.7as well. – Byte Commander Sep 13 '16 at 12:39.bashrc, like my first comment said, it will work. And like Byte Commander said, you can then just callpython2if necessary – Zanna Sep 13 '16 at 19:17pythonsymlink to point topython3instead ofpython2, then you also risk things going wrong because many programs and scripts assumepythonispython2. 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. – edwinksl Sep 13 '16 at 19:22chmod +x'ed. The potential confusion here is that one might get too used to thinking thatpythonispython3and then get confused by a#!/usr/bin/env pythonshebang, 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 yourselfpythonispython3only in your own interactive shells and not anywhere else. – edwinksl Sep 13 '16 at 19:42