I have python3
and python
commands, like this:

- 63,701
- 20
- 147
- 175

- 65
- 7
-
1Linux still depends on python 2 somewhere, leave it there and use python 3 with a virtualenv. – Pietro Mar 28 '21 at 14:50
-
6What do you mean "how can I use python 3.8"? You "use" it in the image you posted. – Lev Levitsky Mar 28 '21 at 14:52
-
I like [this](https://docs.python-guide.org/dev/virtualenvs/) guide as an intro to virtualenvs, but read around a bit as there are several options to manage different python environments, eg [pyenv](https://github.com/pyenv/pyenv), [pipenv](https://pipenv.kennethreitz.org/en/latest/), [pyflow](https://github.com/David-OConnor/pyflow), [poetry](https://python-poetry.org/) and many more, each does a slightly different thing, check out what you need and what they offer. – Pietro Mar 28 '21 at 14:56
-
2**DO NOT** remove Python 2. You'll break half your system and have a nasty time recovering. – user2357112 Mar 28 '21 at 14:58
3 Answers
You can either use it by explicitly calling Python3 via the 'python3' invocation, or if you'd just want to stick with 'python', you could create a virtual environment (e.g. "python3 -m venv venv" then "source venv/bin/activate") and use "python" within the virtual environment.
I'd advise not trying to set "python" to invoke Python 3 at a system level, as there could be system utilities that would expect to be running Python 2 and an underlying change to them could cause issues.

- 1,361
- 7
- 17
Your first option would be to directly call python3 when running you python script I.E:
python3 ~/MyProjects/main.py
instead of
python ~/MyProjects/main.py
If you want to remove python 2 all together - you could.
But as another user stated in the comments, there might be some program on your computer than still depends on python 2.
What I think would fit your needs best is to change the default python version to python3.
This still runs some risk that some program on your computer assumes python
refers to the default python2.
But most programs call /usr/bin/python, and changing the default wont affect those programs.
So in the end changing the default is less risky than deleting python 2, while still giving you the comfortable python3 as the default.
I found this guide from a quick google search
basically - it instructs you to run the following command with root privillages:
update-alternatives --install /usr/bin/python python /usr/bin/python3 1

- 111
- 1
- 3
-
Still not advised. Python2 vs Python3 has some syntax differences in basic things, such as `print "something"` vs `print("something")`. If core system utilities are written expecting 2, this can cause problems still. The safest way to handle this is to use virtualenvs as described in the comments. – Ackack Mar 28 '21 at 15:18
-
I agree using virtualenv is best here. As I said, I believe most system utils reference python2 by its absolute /usr/bin/python path, in which case changing the default wont matter. but yea I agree. – Lior Elbaz Mar 28 '21 at 15:19
I found some question in SE which is related to your question.
setting default python version in ubuntu
Two versions of python on linux. how to make 2.7 the default
Change the Python3 default version in Ubuntu
How to change the default version of Python
They may not be helpful for you. I am going to run those command in my terminal.
python --version
Python 3.9.2
python -V
Python 3.9.2
But, when I run
python2 --version
I get
Python 2.7.18
So, how you should run python program from terminal. You should run python3
instead of python
.

- 30,962
- 25
- 85
- 135