24

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
Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109
Danilo Santos
  • 343
  • 1
  • 2
  • 4

3 Answers3

63

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
spacediver
  • 1,483
  • 1
  • 11
  • 18
Ismam Al Hoque
  • 754
  • 7
  • 5
  • 1
    This works like a cham. Thanks! – Danilo Santos May 07 '22 at 15:27
  • 5
    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. – peschü May 22 '22 at 21:14
  • 1
    So useful an answer. Helped me – George Udosen Aug 09 '22 at 18:38
  • 1
    Gosh, you've saved my hair! I'd contributed some edits to your answer, and also thanks @peschü! – spacediver Aug 24 '22 at 12:07
  • 2
    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 . – Herbert Jan 10 '23 at 10:38
  • 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. – Herbert Jan 10 '23 at 11:05
  • How to uninstall this? I want to reinstall it – Hilman Jan 26 '23 at 10:39
  • How to avoid the prompt for geographic region, so that this can be done in a Dockerfile? – Dan Nissenbaum Feb 22 '23 at 16:13
  • 1
    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. – Dan Nissenbaum Feb 22 '23 at 17:06
  • @DanNissenbaum this can be done in a Dockerfile also if we do `ARG DEBIAN_FRONTEND=noninteractive` as per https://serverfault.com/a/797318/940772 – V-R Jun 17 '23 at 11:35
1

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
IAmBotmaker
  • 322
  • 5
  • 15
1

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://stackoverflow.com/a/72135545/8721632

Sai Saketh
  • 11
  • 1