2

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.

CrYbAbY
  • 92
  • 1
  • 1
  • 11
  • In general, do not remove a Python installation on Linux if there is any chance that it may be the system's default Python (or default Python 3). Likewise, do not replace the symlinks to the default Python's with symlinks to different versions. Different Python installations can coexist perfectly on Linux as long as you are content to specify the version when calling them, for example `python3.8 myscript.py`. Messing with the system Pythons will mess up your machine. – snakecharmerb Oct 25 '20 at 15:14
  • @snakecharmerb a particular problem with replacing the python3 symlink specifically, especially with python3 version >= minimal? that's exactly some of the solutions proposed on questions 43743509 on SO, 410579 on Unix&Linux and elsewhere. Perfectly valid as far as I know (effectively what is done by update-alternatives, nay?). – Yuri Feldman Oct 25 '20 at 20:13

2 Answers2

0

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.

Yuri Feldman
  • 2,354
  • 1
  • 20
  • 23
0

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

Timur Shtatland
  • 12,024
  • 2
  • 30
  • 47
  • I use windows as my regular work station so "setting up multiple virtual environments" for my question is not a right answer I guess. From my perspective, the question was simple, should I or should I not remove python3.6 as I have python3.8 installed on my system. Still, I thank you for you taking your time in writing this explanation. – CrYbAbY Nov 04 '20 at 14:28