https://www.pythonf.cn/read/24249
4.2 编译时提示Could not import runpy module错误
错误信息如下,因为开启了编译优化,但gcc版本过低,升级gcc版本解决。
LD_LIBRARY_PATH=/opt/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 ; \fiCould not import runpy moduleTraceback (most recent call last): File "/opt/Python-3.8.0/Lib/runpy.py", line 15, in import importlib.util File "/opt/Python-3.8.0/Lib/importlib/util.py", line 14, in from contextlib import contextmanager File "/opt/Python-3.8.0/Lib/contextlib.py", line 4, in import _collections_abcSystemError: returned NULL without setting an errorgenerate-posix-vars failedmake[1]: *** [pybuilddir.txt] Error 1make[1]: Leaving directory `/opt/Python-3.8.0'make: *** [profile-opt] Error 2
(1) --enable-optimization和--with-lto做了哪些优化 在stackoverflow上有个关于这个问题的讨论: Python编译优化都做了哪些?大体意思是能够使python提升10%-20%速度。
(2) 升级gcc版本
安装CentOS软件集:yum install -y centos-release-scl
安装编译工具链:yum install -y devtoolset-8-toolchain
启用新的工具链:scl enable devtoolset-8 bash