Segmentation fault while installing Python 3.5: ensurepip

Solution 1:

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

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.patch

Step 3: make && sudo make install

Solution 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.

Solution 3:

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.