title: how to succesfully compile python 3.x
body: <p>Upon attempting to compile python 3.7 I hit <code>Could not import runpy module</code>:</p>
  <pre><code>jeremyr@b88:$ wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tar.xz
  ....
  jeremyr@b88:~/Python-3.7.3$ ./configure --enable-optimizations    
  jeremyr@b88:~/Python-3.7.3$ make clean 
  jeremyr@b88:~/Python-3.7.3$ make -j32 
  .... 
  
  gcc -pthread     -Xlinker -export-dynamic -o Programs/_testembed Programs/_testembed.o libpython3.7m.a -lcrypt -lpthread -ldl  -lutil   -lm  
  ./python -E -S -m sysconfig --generate-posix-vars ;\
  if test $? -ne 0 ; then \
      echo &quot;generate-posix-vars failed&quot; ; \
      rm -f ./pybuilddir.txt ; \
      exit 1 ; \
  fi
  Could not import runpy module
  Traceback (most recent call last):
    File &quot;/home/jeremyr/Python-3.7.3/Lib/runpy.py&quot;, line 15, in &lt;module&gt;
      import importlib.util
    File &quot;/home/jeremyr/Python-3.7.3/Lib/importlib/util.py&quot;, line 14, in &lt;module&gt;
      from contextlib import contextmanager
    File &quot;/home/jeremyr/Python-3.7.3/Lib/contextlib.py&quot;, line 4, in &lt;module&gt;
      import _collections_abc
  SystemError: &lt;built-in function compile&gt; returned NULL without setting an error
  generate-posix-vars failed
  Makefile:603: recipe for target 'pybuilddir.txt' failed
  make[1]: *** [pybuilddir.txt] Error 1
  make[1]: Leaving directory '/home/jeremyr/Python-3.7.3'
  Makefile:531: recipe for target 'profile-opt' failed
  make: *** [profile-opt] Error 2
  
  jeremyr@88:~/Python-3.7.3$ lsb_release -a
  No LSB modules are available.
  Distributor ID: Debian
  Description:    Debian GNU/Linux 8.11 (jessie)
  Release:    8.11
  Codename:   jessie
  
  jeremyr@88:~/Python-3.7.3$ gcc --version 
  gcc (Debian 4.9.2-10+deb8u2) 4.9.2
  Copyright (C) 2014 Free Software Foundation, Inc.
  This is free software; see the source for copying conditions.  There is NO
  warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  
  jeremyr@88:~/Python-3.7.3$ sudo apt upgrade gcc
  Reading package lists... Done
  Building dependency tree       
  Reading state information... Done
  Calculating upgrade... gcc is already the newest version.
  
  jeremyr@b88:~/Python-3.7.3$ echo $PYTHONPATH
  </code></pre>
  <p>Any advice on how to overcome this and install python3.7 appreciated.</p>
  <p>Edit - the solution listed below seems to work for various other python versions, so I changed title to python 3.x from 3.7</p>