如何解决Python 3.11.9的make install编译安装错误?
编译安装Python 3.11.9失败问题解决
问题背景
在预装Python 3.10.12的Ubuntu 22.04系统中,执行make install安装Python 3.11.9时进程异常终止,目标目录未生成lib文件夹且bin文件夹为空。
执行的命令
../configure --prefix=/usr --with-ensurepip=install --enable-optimizations make -j$(nproc) DESTDIR=/home/user/project/myapp.AppDir install
错误信息
错误1(大量类似未定义引用)
/usr/bin/ld: Python/errors.o: in function `_PyErr_Fetch': /home/user/project/src/Python-3.11.9/debug/../Python/errors.c:428: undefined reference to `__gcov_indirect_call' /usr/bin/ld: /home/user/project/src/Python-3.11.9/debug/../Python/errors.c:428: undefined reference to `__gcov_indirect_call_profiler_v4' /usr/bin/ld: /home/user/project/src/Python-3.11.9/debug/../Python/errors.c:428: undefined reference to `__gcov_time_profiler_counter' /usr/bin/ld: /home/user/project/src/Python-3.11.9/debug/../Python/errors.c:428: undefined reference to `__gcov_time_profiler_counter' /usr/bin/ld: Python/errors.o: in function `PyErr_GivenExceptionMatches': /home/user/project/src/Python-3.11.9/debug/../Python/errors.c:255: undefined reference to `__gcov_indirect_call' /usr/bin/ld: /home/user/project/src/Python-3.11.9/debug/../Python/errors.c:255: undefined reference to `__gcov_indirect_call_profiler_v4' /usr/bin/ld: /home/user/project/src/Python-3.11.9/debug/../Python/errors.c:255: undefined reference to `__gcov_time_profiler_counter' /usr/bin/ld: /home/user/project/src/Python-3.11.9/debug/../Python/errors.c:255: undefined reference to `__gcov_time_profiler_counter' /usr/bin/ld: Python/errors.o: in function `PyErr_ExceptionMatches': /home/user/project/src/Python-3.11.9/debug/../Python/errors.c:294: undefined reference to `__gcov_indirect_call' /usr/bin/ld: /home/user/project/src/Python-3.11.9/debug/../Python/errors.c:294: undefined reference to `__gcov_indirect_call_profiler_v4' /usr/bin/ld: /home/user/project/src/Python-3.11.9/debug/../Python/errors.c:294: undefined reference to `__gcov_time_profiler_counter' /usr/bin/ld: /home/user/project/src/Python-3.11.9/debug/../Python/errors.c:294: undefined reference to `__gcov_time_profiler_counter'
错误2
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE collect2: error: ld returned 1 exit status make: *** [Makefile:1203: Programs/_freeze_module] Error 1
错误3(进程终止前最后信息)
# This is an expensive target to build and it does not have proper # makefile dependency information. So, we create a "stamp" file # to record its completion and avoid re-running it.
解决步骤
1. 清理残留编译文件
彻底清除之前的编译目录和临时文件,避免旧配置干扰:
cd /home/user/project/src/Python-3.11.9/debug make clean cd .. rm -rf debug
2. 安装编译依赖
确保系统具备Python编译所需的全部依赖:
sudo apt-get update sudo apt-get install build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python3-openssl git
3. 重新配置编译参数
创建新的编译目录,使用调整后的configure命令,禁用gcov避免链接错误,同时指定独立安装目录防止覆盖系统Python:
mkdir build && cd build ../configure --prefix=/usr/local/python3.11 --with-ensurepip=install --enable-optimizations --disable-gcov
4. 分步编译安装
先单独执行编译,确认无错误后再执行安装:
# 编译,使用全部CPU核心加速 make -j$(nproc) # 安装到指定DESTDIR make DESTDIR=/home/user/project/myapp.AppDir install
说明
--disable-gcov:直接禁用gcov代码覆盖率检测,解决__gcov_*系列未定义引用问题。--prefix=/usr/local/python3.11:将Python安装到独立目录,避免与系统预装的Python 3.10冲突。- 分步执行
make和make install:便于单独排查编译或安装阶段的问题。
内容的提问来源于stack exchange,提问作者Sun Bear
相关产品推荐
相关产品推荐

