How to install python3.6 on Ubuntu 22.04

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

3 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
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
10

If you need it to install with pyenv, you could try this one:

$ sudo apt install clang -y
$ CC=clang pyenv install 3.6.9
0

As on Aug 2nd 2023, if anyone is still stuck with Segmentation fault (core dumped) issue. Here's the solution that worked for me. Thanks to Issue45700 - .

Ubuntu 22.04 comes with gcc 11. So let us install gcc-10 and compile Python with it.

Below are the steps to incorporate Workaround1 mentioned in Issue45700 -

apt-get install gcc-10 -y
< Download and extract python >
CC="gcc-10" ./configure
< Install python using make >

You can use additional flags mentioned in

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like