操作環(huán)境:CentOS 7
、Gcc 4.8.5
、Python 3.10.0
系統(tǒng)上已經(jīng)有 2.x
,3.6
版本的 Python
了,但是還是想裝一個 3.10
的。因為剛寫的腳本文件是較高版本的,在 3.6
上無法正常運行,Python
語法不是很了解,只能從環(huán)境上下手了。
【注】Python 其他版本也適用,畢竟是編譯器的問題,并非 Python 版本問題。
下載源碼文件,然后開始執(zhí)行操作:
./configure --enable-optimizations
make
sudo make install
然后報錯如下,下面是兩個機器不同的報錯:
# 報錯一:
gcc -pthread -Xlinker -export-dynamic -o python Programs/python.o libpython3.10.a -lcrypt -lpthread -ldl -lutil -lm -lm
./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 "/opt/Python-3.10.0/Lib/runpy.py", line 15, in <module>
import importlib.util
File "/opt/Python-3.10.0/Lib/importlib/util.py", line 14, in <module>
from contextlib import contextmanager
File "/opt/Python-3.10.0/Lib/contextlib.py", line 4, in <module>
import _collections_abc
SystemError: <built-in function compile> returned NULL without setting an exception
generate-posix-vars failed
make: *** [pybuilddir.txt] Error 1
# 報錯二:
make build_all CFLAGS_NODIST=" -fprofile-use -fprofile-correction" LDFLAGS_NODIST=""
make[1]: Entering directory `/usr/local/src/Python-3.10.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 "/opt/Python-3.10.0/Lib/runpy.py", line 15, in <module>
import importlib.util
File "/opt/Python-3.10.0/Lib/importlib/util.py", line 14, in <module>
from contextlib import contextmanager
File "/opt/Python-3.10.0/Lib/contextlib.py", line 4, in <module>
import _collections_abc
SystemError: <built-in function compile> returned NULL without setting an error
generate-posix-vars failed
make[1]: *** [pybuilddir.txt] Error 1
make[1]: Leaving directory `/opt/Python-3.10.0'
make: *** [profile-opt] Error 2
導致原因
在低版本的gcc
版本,使用 gcc
命令并帶有 --enable-optimizations
參數(shù)時會出現(xiàn)上面問題。在 gcc 8.1.0
此問題已經(jīng)修復。
解決方法
1、升級gcc
至 8.1.0
,不是很推薦,可能會影響其他軟件的編譯。
2、./configure
參數(shù)中去掉 --enable-optimizations
。然后執(zhí)行下面的命令:
./configure
make
sudo make install
如果還不行就將解壓的 Python
目錄刪除掉,重新解壓,然后重新執(zhí)行上面的命令。文章來源:http://www.zghlxwxcb.cn/news/detail-772325.html
Python
鎮(zhèn)樓?。?!點下關注好不好,我想申請博客專家!??! 哭唧唧!??!
個人博客: Roc’s Blog文章來源地址http://www.zghlxwxcb.cn/news/detail-772325.html
到了這里,關于解決 Centos 安裝 Python 3.10 的報錯: Could not import runpy module的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!