How to install python3.6 on Ubuntu 22.04

Viewed 6603

I need to install this specific python version, to prepare a developer environment, because I'm maintaining a system with multiple libraries based on python 3.6.9. I recently installed Ubuntu 22.04 on my laptop, but I had no success trying to install this python version.

I tried to install with apt-get after adding the deadsneak repository, but this python version is not available.

I tried installing from source by compiling, but it did not work. Running sudo make altinstall exited with this error:

Segmentation fault (core dumped)
make: *** [Makefile:1112: altinstall] Erro 139
2 Answers

I have faced the same problems and could make it work by adding some additional flags when running ./configure

Here are my steps:

Step 1 – Prerequsities

sudo apt-get install -y make 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 \
libgdbm-dev libnss3-dev libedit-dev libc6-dev

Step 2 – Download Python 3.6

wget https://www.python.org/ftp/python/3.6.15/Python-3.6.15.tgz

tar -xzf Python-3.6.15.tgz

Step 3 – Compile Python Source

cd Python-3.6.15
./configure --enable-optimizations  -with-lto  --with-pydebug
make -j 8  # adjust for number of your CPU cores
sudo make altinstall

Step 4 – Check the Python Version

python3.6 -V

Although the original question and the above answer was initially useful to me, I have to say that since python 3.6 is no longer maintained since the end of 2021, I finally had to switch to a more recent version because pipenv could detect the manually compiled python 3.6 but locking consistently failed.

Related