I can observe both versions of Python2 and Python3 in my Raspberry Pi.
Both of them were by default.
Why do we have both the version of python in Raspbian?
Is it safe to uninstall Python2 and only keep Python3?
Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It only takes a minute to sign up.
Sign up to join this communityIs it safe to uninstall Python2 and only keep Python3?
To be "safe" as in "don't break anything"? Probably not. But Python2 doesn't occupy much space - about 3MB on your SD card. And if you don't use it, it doesn't consume any resources.
It can be annoying to have python2 as the default, but you can cure that annoyance without removing it:
update-alternatives
:Verify your system's baseline (this is from my system):
$ python --version
Python 2.7.16
$ python3 --version
Python 3.7.3
To make python
use python3
:
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10
The response should be:
update-alternatives: using /usr/bin/python3 to provide /usr/bin/python (python) in auto mode
Check baseline again:
$ python --version
Python 3.7.3
$ python3 --version
Python 3.7.3
See man update-alternatives
for details. If you want to "undo" this:
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 10
Which should yield this response:
update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in auto mode
Type sudo apt -s remove python2
and check out the list of packages which would have to be removed. You'll most likely see that half of your system will be gone if you do remove it.
You are likely to break things, but it would require significant effort to determine.
Why do you WANT to delete it, it uses little space and there are lots of other programs you don't use - do you plan to delete these too?
You could also install the package python-is-python3, which symlinks /usr/bin/python to python3.
sudo apt install python-is-python3