Segmentation fault while installing Python 3.5: ensurepip
Matthew Martinez
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...
->
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:
Output of make:
Output of make install:
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/", 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/", 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/", 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/", 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/", 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/", 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/", 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 3 Answers
I found the solution here:
Step 1: create file segfault.patch:
--- 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.patchStep 3: make && sudo make install
2Miniconda
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.
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