Linux 安装Python3 的步骤以及遇到的问题.

在尝试升级Linux系统中的Python到3.x版本时,用户遇到了编译错误,具体涉及gcc-pthread、importlib.util模块以及runpy的导入问题。通过执行makeclean,然后sudomake和sudomakeinstall的顺序,成功解决了编译过程中出现的SystemError,使Python安装过程得以继续。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安装步骤 详见:

Linux 升级 Python 至 3.x - 知乎 (zhihu.com)

遇到的问题:

make && make install b编译时分别报错:

"gcc -pthread     -Xlinker -export-dynamic -o python Programs/python.o libpython3.9.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/module/Python3.9.13/Python-3.9.13/Lib/runpy.py", line 15, in <module>
    import importlib.util
  File "/opt/module/Python3.9.13/Python-3.9.13/Lib/importlib/util.py", line 2, in <module>
    from . import abc
  File "/opt/module/Python3.9.13/Python-3.9.13/Lib/importlib/abc.py", line 17, in <module>
    from typing import Protocol, runtime_checkable
  File "/opt/module/Python3.9.13/Python-3.9.13/Lib/typing.py", line 21, in <module>
    import collections
SystemError: <built-in function compile> returned NULL without setting an error
generate-posix-vars failed
make: *** [pybuilddir.txt] 错误 1
"

 解决方法:

# make clean
#sudo make 
#sudo make install

解决方法参考:(126条消息) linux服务器安装python 3.9出现Could not import runpy module_linux 无法导入runpy模块_xiaoxiaoxuexi123的博客-优快云博客

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值