Should i remove Python 3.6 while installing Python 3.8 or newer?

16.6k views Asked by At

I tried to install a certain python module that required python 3.6 minimum to work properly so I checked my version using python --version which gave me the output of Python 2.7.17 and then used python3 --version giving me Python 3.6.9. Now, I know for a fact that i have Python 3.8 installed because I ran apt install python3.8 just before checking the version.

If someone wants to know what my system is running; I am currently running Elementary OS 5.1.7 Hera.

EDIT: (IDK what term to use, I want to say I am done going through answers, and I liked none.) After a while of whacking my brain, I decided not to uninstall the 3.6 version as It may have version specific modules which if removed may cause other installed programs to break.
Since I just use Linux for my college-work, It wont matter if more than one versions are installed anyway.

Sorry for any mistakes I may have made, I was never good at this kind of things.

2

There are 2 answers

0
Yuri Feldman On

This question is more appropriate for Unix & Linux.

Python installations (more generally, versioned installations of software) co-exist on linux using version numbers. You can likely run Python 3.8 using the python3.8 command (or else, locate where you installed it and run from there / add the location to the PATH environment variable to run directly).

Likewise, for each python version you can install its own package manager (e.g. install pip3.8 by python3.8 -m pip install pip) and use it to install packages for that python version. (As different projects require different sets of packages, the general practice is to create a "virtual environment", i.e. a separate copy of the needed version of python, pip and their package installation folders for each project, and install the required packages there - for more information see e.g. this excellent answer).

Regarding the command python3 (usually /usr/bin/python3) is just a symbolic link, you can replace it with the version you like (as long as it remains compatible with what the system expects - i.e. python3 of version no less than your built-in python3/python3-minimal, otherwise you will probably break something), e.g. assuming which python3 gives you /usr/bin/python3, you can

sudo rm /usr/bin/python3 #remove existing link
sudo ln /usr/bin/python3.8 /usr/bin/python3 # create a new link to the version of your choice

(although a better alternative could be instead aliasing it alias python3='/usr/bin/python3.8' and adding this to ~/.bashrc).

Whatever you do, do not uninstall python3-minimal as it is - at least, on Ubuntu - required by the system and uninstalling or changing it will likely break the system.

1
Timur Shtatland On

Use conda to install and manage different versions of Python (or lots of other software, for that matter). Install different Python versions in separate conda environments. For example:

Find what python versions are available:

conda search python

Output (as of the time of writing, in the future I expect that the latest Python versions will be higher):

Loading channels: done
# Name                       Version           Build  Channel             
python                         1.0.1               0  conda-forge         
python                           1.2               0  conda-forge         
...
     
python                         3.9.0      h88f2d9e_1  pkgs/main           
python                         3.9.0 ha017127_4_cpython  conda-forge         

Install the Python versions you need in separate environments. Here, install Python 3.9.0 in environment named python39:

conda create --name python39 python=3.9.0

Switching environments is easy:

conda activate python39
# python is now 3.9.0
conda deactivate
# back to the default python

or (deprecated now):

source activate python39
source deactivate

SEE ALSO:

conda docs: Managing environments