7

I got a segmentation fault while trying to install Python 3.5 on Ubuntu 21.10.

$ guettli@p15:~$ pyenv install 3.5.8

Downloading Python-3.5.8.tar.xz...
-> https://www.python.org/ftp/python/3.5.8/Python-3.5.8.tar.xz
Installing Python-3.5.8...

BUILD FAILED (Ubuntu 21.10 using python-build 20180424)

Inspect or clean up the working tree at /tmp/python-build.20211119144903.305257
Results logged to /tmp/python-build.20211119144903.305257.log

Last 10 log lines:
if test "xupgrade" != "xno"  ; then \
    case upgrade in \
        upgrade) ensurepip="--upgrade" ;; \
        install|*) ensurepip="" ;; \
    esac; \
     ./python -E -m ensurepip \
        $ensurepip --root=/ ; \
fi
Segmentation fault (core dumped)

The same happens, when I install Python-3.5.10.tar.xz (without pyenv). What can I do now?

Version: Ubuntu 21.10
Output of configure: https://pastebin.com/rie17s8Z
Output of make: https://pastebin.com/F3C4evR6
Output of make install: https://paste2.org/LKxHUYkM

With PYTHONFAULTHANDLER:

guettli@p15:~/Downloads/Python-3.5.10$ PYTHONFAULTHANDLER=1 LANG=C python3.5 -m ensurepip
Fatal Python error: Segmentation fault

Current thread 0x00007fb703b40740 (most recent call first):
  File "/usr/local/lib/python3.5/ctypes/__init__.py", line 276 in _reset_cache
  File "/usr/local/lib/python3.5/ctypes/__init__.py", line 541 in <module>
  File "<frozen importlib._bootstrap>", line 222 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 697 in exec_module
  File "<frozen importlib._bootstrap>", line 673 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 957 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 968 in _find_and_load
  File "/usr/local/lib/python3.5/uuid.py", line 464 in <module>
  File "<frozen importlib._bootstrap>", line 222 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 697 in exec_module
  File "<frozen importlib._bootstrap>", line 673 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 957 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 968 in _find_and_load
  File "/tmp/tmppx73eqwt/pip-9.0.1-py2.py3-none-any.whl/pip/_vendor/requests/packages/urllib3/filepost.py", line 4 in <module>
  File "<frozen importlib._bootstrap>", line 634 in _load_backward_compatible
  File "<frozen importlib._bootstrap>", line 664 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 957 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 968 in _find_and_load
  File "/tmp/tmppx73eqwt/pip-9.0.1-py2.py3-none-any.whl/pip/_vendor/requests/packages/urllib3/request.py", line 7 in <module>
  File "<frozen importlib._bootstrap>", line 634 in _load_backward_compatible
  File "<frozen importlib._bootstrap>", line 664 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 957 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 968 in _find_and_load
  File "/tmp/tmppx73eqwt/pip-9.0.1-py2.py3-none-any.whl/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 41 in <module>
  File "<frozen importlib._bootstrap>", line 634 in _load_backward_compatible
  File "<frozen importlib._bootstrap>", line 664 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 957 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 968 in _find_and_load
  File "/tmp/tmppx73eqwt/pip-9.0.1-py2.py3-none-any.whl/pip/_vendor/requests/packages/urllib3/__init__.py", line 8 in <module>
  File "<frozen importlib._bootstrap>", line 634 in _load_backward_compatible
  File "<frozen importlib._bootstrap>", line 664 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 957 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 968 in _find_and_load
  File "<frozen importlib._bootstrap>", line 222 in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1015 in _handle_fromlist
  File "/tmp/tmppx73eqwt/pip-9.0.1-py2.py3-none-any.whl/pip/_vendor/requests/packages/__init__.py", line 27 in <module>
  File "<frozen importlib._bootstrap>", line 634 in _load_backward_compatible
  File "<frozen importlib._bootstrap>", line 664 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 957 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 968 in _find_and_load
  File "<frozen importlib._bootstrap>", line 222 in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 943 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 968 in _find_and_load
  File "<frozen importlib._bootstrap>", line 222 in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 943 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 968 in _find_and_load
  File "/tmp/tmppx73eqwt/pip-9.0.1-py2.py3-none-any.whl/pip/_vendor/requests/__init__.py", line 62 in <module>
  File "<frozen importlib._bootstrap>", line 634 in _load_backward_compatible
  File "<frozen importlib._bootstrap>", line 664 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 957 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 968 in _find_and_load
  File "<frozen importlib._bootstrap>", line 222 in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 943 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 968 in _find_and_load
  File "<frozen importlib._bootstrap>", line 222 in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 943 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 968 in _find_and_load
  File "<frozen importlib._bootstrap>", line 222 in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 943 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 968 in _find_and_load
  File "/tmp/tmppx73eqwt/pip-9.0.1-py2.py3-none-any.whl/pip/__init__.py", line 21 in <module>
  File "<frozen importlib._bootstrap>", line 634 in _load_backward_compatible
  File "<frozen importlib._bootstrap>", line 664 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 957 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 968 in _find_and_load
  File "/usr/local/lib/python3.5/ensurepip/__init__.py", line 40 in _run_pip
  File "/usr/local/lib/python3.5/ensurepip/__init__.py", line 116 in bootstrap
  File "/usr/local/lib/python3.5/ensurepip/__init__.py", line 209 in _main
  File "/usr/local/lib/python3.5/ensurepip/__main__.py", line 4 in <module>
  File "/usr/local/lib/python3.5/runpy.py", line 85 in _run_code
  File "/usr/local/lib/python3.5/runpy.py", line 193 in _run_module_as_main
Segmentation fault (core dumped)
10
  • What does the log say?
    – user535733
    Commented Nov 19, 2021 at 14:19
  • @user535733 in above output you see the last ten lines of the output. There is nothing which looks relevant in the lines above these ten lines.
    – guettli
    Commented Nov 19, 2021 at 15:05
  • 1
    @guetti, indeed. But that begs the question why is a shell script being output to your log? Look at more than the last 10 lines.
    – user535733
    Commented Nov 19, 2021 at 15:56
  • Is there anything unique to your installation? I've installed 3.5.10 (via the .tar.xz) on a 20.04 an a 21.04 installation in a virtual machine without complaint. Not sure what might be preventing you from installing this specific version ...
    – matigo
    Commented Nov 22, 2021 at 15:12
  • 1
    @CarlesMateo the same error happens if I use Python 3.5.10. Unfortunately I need Python 3.5 for this case.
    – guettli
    Commented Nov 23, 2021 at 9:28

4 Answers 4

10

I found the solution here: https://giters.com/pyenv/pyenv/issues/1889

Step 1: create file segfault.patch with the following contents:

--- Include/objimpl.h
+++ Include/objimpl.h
@@ -250,7 +250,7 @@
         union _gc_head *gc_prev;
         Py_ssize_t gc_refs;
     } gc;
-    double dummy;  /* force worst-case alignment */
+    long double dummy;  /* force worst-case alignment */
 } PyGC_Head;

 extern PyGC_Head *_PyGC_generation0;
--- Objects/obmalloc.c
+++ Objects/obmalloc.c
@@ -643,8 +643,8 @@
  *
  * You shouldn't change this unless you know what you are doing.
  */
-#define ALIGNMENT               8               /* must be 2^N */
-#define ALIGNMENT_SHIFT         3
+#define ALIGNMENT               16               /* must be 2^N */
+#define ALIGNMENT_SHIFT         4

 /* Return the number of bytes in size class I, as a uint. */
 #define INDEX2SIZE(I) (((uint)(I) + 1) << ALIGNMENT_SHIFT)

Step 2: apply the patch:

user@host:Python-3.5.10$ patch -p0 < segfault.patch

Step 3:

user@host:Python-3.5.10$ make -j 8  # adapt to your number of CPU cores

Step 4:

Either:

user@host:Python-3.5.10$ sudo make altinstall  # if you want only python3.6

Or

user@host:Python-3.5.10$ sudo make install  # if you want systemwide python as well
4
  • i'm already on Impish. i tried it, a voted to awesome answered. Commented Nov 26, 2021 at 14:14
  • 1
    Almost give up. Your patch worked for Python 3.6.15 in Kubuntu 21.10. Although I've already installed it from source, I made the patch, executed make && sudo make altinstall and now python3.6 -m pip list doesn't return a segmentation fault, thanks. Upvoted!
    – gorandp
    Commented Jun 3, 2022 at 14:54
  • 1
    You've saved my hair! Worked with vanilla python 3.6.15 on ubuntu 22.04.1.
    – spacediver
    Commented Aug 24, 2022 at 13:18
  • Also works in Python 3.5.9 using an alpine v3.17.2 VM! Before, pyenv install 3.7.9 was failing on ./python -c 'import ctypes'. Thanks. Commented Feb 23, 2023 at 18:36
4

Apparently it's enough to set CC=gcc-10 before building Python 3.5 and 3.6 on Ubuntu 22.04 LTS, as per the pyenv issue:

sudo apt install gcc-10
CC=gcc-10 pyenv install 3.6.13

(I'm not using Pyenv myself, but compiling from source, and this workaround fixed the segfaults for me.)

2

Miniconda

I suggest installing miniconda to manage your virtual environment and installing the desired python version within the newly created env.

In my opinion, it's a decent solutions not as bloated as anaconda and you can still use pip, poetry or whatever package management software that you would like.

1
  • Short and useful Commented Jun 23, 2022 at 4:51
1

I tried this and got the same error; also tried 3.5.10 the best in this release line and still the same. I assumed it was a problem with pyenv and tried 2.2.0 but still the same result. So I downloaded Python 3.5.8 and proceeded to install manually (at the install directory, see Python docs) with:

./configure --with-pydebug --enable-optimizations --with-lto

make

But in make the python got hung up on testing the distribution. So the advice is don't use any options with ./configure. Then run:

make

sudo make install or sudo make altinstall

There is more than one problem in this build 3.5.8 of which the main reason why pyenv doesn't work seems to be due to this:

/home/<me>/Python-3.5.8/Modules/nismodule.c:17:10: fatal error: rpc/rpc.h: No such file or directory 17 | #include <rpc/rpc.h>

Then use Pycharm to build you project or simply use venv or virtulenv.

3
  • Thank you for reproducing it. Unfortunately I still get the seg-fault, even if I use a newly extracted sources and don't provide any options to configure. It happens during sudo make altinstall, too.
    – guettli
    Commented Nov 23, 2021 at 13:04
  • @guettli could you give more info: what you did exactly, and the output? It could be that 3.5.8 has a fatal bug in the build but I can still produce an executable. Commented Nov 23, 2021 at 14:28
  • you said that you can reproduce the error. Nice. I don't do anything special. Just untar, configure, make, sudo make install. I uploaded the logs of each step to the question.
    – guettli
    Commented Nov 23, 2021 at 15:27

You must log in to answer this question.

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