電子商務(wù)網(wǎng)站建設(shè)項(xiàng)目規(guī)劃書排名點(diǎn)擊工具
操作環(huán)境:CentOS 7
、Gcc 4.8.5
、Python 3.10.0
系統(tǒng)上已經(jīng)有 2.x
,3.6
版本的 Python
了,但是還是想裝一個(gè) 3.10
的。因?yàn)閯倢懙哪_本文件是較高版本的,在 3.6
上無法正常運(yùn)行,Python
語法不是很了解,只能從環(huán)境上下手了。
【注】Python 其他版本也適用,畢竟是編譯器的問題,并非 Python 版本問題。
下載源碼文件,然后開始執(zhí)行操作:
./configure --enable-optimizations
make
sudo make install
然后報(bào)錯(cuò)如下,下面是兩個(gè)機(jī)器不同的報(bào)錯(cuò):
# 報(bào)錯(cuò)一:
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.utilFile "/opt/Python-3.10.0/Lib/importlib/util.py", line 14, in <module>from contextlib import contextmanagerFile "/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
# 報(bào)錯(cuò)二:
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.utilFile "/opt/Python-3.10.0/Lib/importlib/util.py", line 14, in <module>from contextlib import contextmanagerFile "/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
導(dǎo)致原因
在低版本的gcc
版本,使用 gcc
命令并帶有 --enable-optimizations
參數(shù)時(shí)會(huì)出現(xiàn)上面問題。在 gcc 8.1.0
此問題已經(jīng)修復(fù)。
解決方法
1、升級(jí)gcc
至 8.1.0
,不是很推薦,可能會(huì)影響其他軟件的編譯。
2、./configure
參數(shù)中去掉 --enable-optimizations
。然后執(zhí)行下面的命令:
./configure
make
sudo make install
如果還不行就將解壓的 Python
目錄刪除掉,重新解壓,然后重新執(zhí)行上面的命令。
Python
鎮(zhèn)樓!!!點(diǎn)下關(guān)注好不好,我想申請(qǐng)博客專家!!! 哭唧唧!!!
個(gè)人博客: Roc’s Blog