python 3.8 Could not import runpy module

文章目录

  • 环境
  • 相关报错
  • 导致原因
  • 解决方法如下

环境

  • CentOS 7
  • Gcc 4.8.5
  • Python 3.8.0

相关报错

make build_all CFLAGS_NODIST=" -fprofile-use -fprofile-correction" LDFLAGS_NODIST=""
make[1]: Entering directory `/usr/local/src/Python-3.8.0'
./python -E -S -m sysconfig --generate-posix-vars ;\
if test $? -ne 0 ; then \
	echo "generate-posix-vars failed" ; \
	rm -f ./pybuilddir.txt ; \
	exit 1 ; \
fi
Could not import runpy module
Traceback (most recent call last):
  File "/usr/local/src/Python-3.8.0/Lib/runpy.py", line 15, in 
    import importlib.util
  File "/usr/local/src/Python-3.8.0/Lib/importlib/util.py", line 14, in 
    from contextlib import contextmanager
  File "/usr/local/src/Python-3.8.0/Lib/contextlib.py", line 4, in 
    import _collections_abc
SystemError:  returned NULL without setting an error
generate-posix-vars failed
make[1]: *** [pybuilddir.txt] Error 1
make[1]: Leaving directory `/usr/local/src/Python-3.8.0'
make: *** [profile-opt] Error 2

导致原因

  • 在低版本的gcc版本中带有--enable-optimizations参数时会出现上面问题
  • gcc 8.1.0修复此问题

解决方法如下

  • 1、升级gcc至8.1.0【不推荐】
  • 2、./configure参数中去掉--enable-optimizations

refs: https://bugs.python.org/issue34112

你可能感兴趣的:(python,python)