3

I have Ubuntu 18.04 LST with Python 2.7.17 and Python 3.6.9 preinstalled.

I have installed Python 3.8.2 via:

sudo apt update

sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget

sudo wget https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tar.xz

tar -xf Python-3.8.2.tar.xz

cd Python-3.8.2

./configure --enable-optimizations

make -j 8

sudo make altinstall

The default versions for ~$ python -V and ~$ python3 -V are then:

Python 2.7.17
Python 3.6.9

When I run ~$ ls -l /usr/bin/python*, I get the following (see image for full output):

-rwxr-xr-x 1 root root 3637096 Apr 15 13:20 /usr/bin/python2.7
-rwxr-xr-x 2 root root 4526456 Apr 17 21:56 /usr/bin/python3.6
-rwxr-xr-x 1 root root 5203488 Oct 28  2019 /usr/bin/python3.8

python versions installed on Ubuntu

I want to know how to remove Python 3.8.2 without damaging the preinstalled versions Python 2.7.17 and Python 3.6.17?

For further information:

I want to do this to install TensorFlow with GPU support. As per TensorFlow documentation TensorFlow: Package location, it only has support up to Python3.7.

Or would it be possible to have several versions of Python installed without affecting Ubuntu functionality?

Also, how do I make sure that when I install packages via pip or pip3, those packages are installed for the desired Python version, e.g. Python 3.8.2?

Thanks in advance for your help!

1 Answer 1

1

Installing Python by compiling alongside the default version it can lead to a good amount of issues because of all the Python libraries shared with the default version, and even some Ubuntu packages depending on the default versions of their Python dependencies.

Using a virtual environments tool like pyenv gets rid of all these issues. It allows you to create an isolated environment using mostly any Python version, isolating its installed packages from other environments and the system itself. You can activate the environment (which overrides commands as python for the custom version) and deactivate it at any time.

Just a hint, the Ubuntu dependencies can be a bit tricky to find on the docs, so here they are:

sudo apt-get install -y build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
xz-utils tk-dev libffi-dev liblzma-dev python-openssl git
1
  • Thank you very much for your answer Matias, but I am looking to replace remove Python 3.8.2 without damaging the OS, so I can install it as virtual environment or as you have suggested. May 11, 2020 at 15:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .