How to install python3.6 on Ubuntu 22.04
Asked Answered
D

3

34

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
Davena answered 3/5, 2022 at 16:17 Comment(0)
S
86

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
Shine answered 6/5, 2022 at 2:31 Comment(11)
This works like a cham. Thanks!Davena
Thanks a lot! This helped me, I had the same problem! If you have more than one CPU core and enough memory, make -j 8 altinstall will use, for example, 8 cores for building.Elum
So useful an answer. Helped meSemiconductor
Gosh, you've saved my hair! I'd contributed some edits to your answer, and also thanks @peschü!Drawback
Just to give y'all a ballpark, it took about 15-30 minutes - didn't accurately time, went for coffee - on Intel Core i7-6700HQ .Mononuclear
It seems like installing packages through pip go from source this way (slow), and packages without sources on pypi like tensorflow are a pain to install. I've discarded this method of using legacy python versions and simply ported some of the legacy code of the package I use. I might have done something wrong, but please consider this before going through this rabbit hole.Mononuclear
How to uninstall this? I want to reinstall itSnyder
How to avoid the prompt for geographic region, so that this can be done in a Dockerfile?Bristol
For anyone else running into this, the component that expects user input is the tk-dev component. Just removing this from the installation - and the Python3.6 installation succeeded. Also, to access pip, use pip3.6 (and python3.6 for python). Just calling pip3 won't work.Bristol
@DanNissenbaum this can be done in a Dockerfile also if we do ARG DEBIAN_FRONTEND=noninteractive as per serverfault.com/a/797318/940772Precedence
For everyone finding this who wants to have a libpython3.6m.so.1.0 file: add --enable-shared to the ./configure command.Leveret
B
6

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 - https://bugs.python.org/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 https://mcmap.net/q/434043/-how-to-install-python3-6-on-ubuntu-22-04

Bainter answered 2/8, 2023 at 12:25 Comment(1)
For me gcc-9 works, you gave me a idea how to fix.Linis
S
4

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
Scalpel answered 16/12, 2022 at 15:11 Comment(1)
Why does this work?Genni

© 2022 - 2024 — McMap. All rights reserved.