在Debian 11上用checkinstall制作Python 3.12安装包时出错
解决Debian 11下用checkinstall制作Python 3.12 deb包的pip相关报错
问题背景
在Debian 11系统使用checkinstall 1.6.3制作Python 3.12的deb安装包,此前成功制作过Python 3.11包。执行以下命令后出现pip相关报错:
./configure --enable-optimizations --enable-shared --prefix=/usr make -j $(nproc) make -n altinstall > make_altinstall.sh chmod +x make_altinstall.sh sudo checkinstall -D ./make_altinstall.sh
报错信息
ERROR: Exception: Traceback (most recent call last): File "/tmp/tmpklvy9437/pip-23.2.1-py3-none-any.whl/pip/_internal/cli/base_command.py", line 180, in exc_logging_wrapper status = run_func(*args) ^^^^^^^^^^^^^^^ File "/tmp/tmpklvy9437/pip-23.2.1-py3-none-any.whl/pip/_internal/cli/req_command.py", line 248, in wrapper return func(self, options, args) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/tmpklvy9437/pip-23.2.1-py3-none-any.whl/pip/_internal/commands/install.py", line 324, in run session = self.get_default_session(options) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/tmpklvy9437/pip-23.2.1-py3-none-any.whl/pip/_internal/cli/req_command.py", line 98, in get_default_session self._session = self.enter_context(self._build_session(options)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/tmpklvy9437/pip-23.2.1-py3-none-any.whl/pip/_internal/cli/req_command.py", line 125, in _build_session session = PipSession( ^^^^^^^^^^^ File "/tmp/tmpklvy9437/pip-23.2.1-py3-none-any.whl/pip/_internal/network/session.py", line 342, in __init__ self.headers["User-Agent"] = user_agent() ^^^^^^^^^^^^ File "/tmp/tmpklvy9437/pip-23.2.1-py3-none-any.whl/pip/_internal/network/session.py", line 175, in user_agent setuptools_dist = get_default_environment().get_distribution("setuptools") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/tmpklvy9437/pip-23.2.1-py3-none-any.whl/pip/_internal/metadata/importlib/_envs.py", line 188, in get_distribution return next(matches, None) ^^^^^^^^^^^^^^^^^^^ File "/tmp/tmpklvy9437/pip-23.2.1-py3-none-any.whl/pip/_internal/metadata/importlib/_envs.py", line 183, in <genexpr> matches = ( ^ File "/tmp/tmpklvy9437/pip-23.2.1-py3-none-any.whl/pip/_internal/metadata/base.py", line 612, in iter_all_distributions for dist in self._iter_distributions(): File "/tmp/tmpklvy9437/pip-23.2.1-py3-none-any.whl/pip/_internal/metadata/importlib/_envs.py", line 176, in _iter_distributions for dist in finder.find_eggs(location): File "/tmp/tmpklvy9437/pip-23.2.1-py3-none-any.whl/pip/_internal/metadata/importlib/_envs.py", line 144, in find_eggs yield from self._find_eggs_in_dir(location) File "/tmp/tmpklvy9437/pip-23.2.1-py3-none-any.whl/pip/_internal/metadata/importlib/_envs.py", line 115, in _find_eggs_in_dir with os.scandir(location) as it: ^^^^^^^^^^^^^^^^^^^^ FileNotFoundError: [Errno 2] No such file or directory: '' Traceback (most recent call last): File "<frozen runpy>", line 198, in _run_module_as_main File "<frozen runpy>", line 88, in _run_code File "/home/thomas/Downloads/Python-3.12.0/Lib/ensurepip/__main__.py", line 5, in <module> sys.exit(ensurepip._main()) ^^^^^^^^^^^^^^^^^ File "/home/thomas/Downloads/Python-3.12.0/Lib/ensurepip/__init__.py", line 284, in _main return _bootstrap( ^^^^^^^^^^^ File "/home/thomas/Downloads/Python-3.12.0/Lib/ensurepip/__init__.py", line 200, in _bootstrap return _run_pip([*args, *_PACKAGE_NAMES], additional_paths) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/thomas/Downloads/Python-3.12.0/Lib/ensurepip/__init__.py", line 101, in _run_pip return subprocess.run(cmd, check=True).returncode ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/thomas/Downloads/Python-3.12.0/Lib/subprocess.py", line 571, in run raise CalledProcessError(retcode, process.args, subprocess.CalledProcessError: Command '['/home/thomas/Downloads/Python-3.12.0/python', '-W', 'ignore::DeprecationWarning', '-c', '\nimport runpy\nimport sys\nsys.path = [\'/tmp/tmpklvy9437/pip-23.2.1-py3-none-any.whl\'] + sys.path\nsys.argv[1:] = [\'install\', \'--no-cache-dir\', \'--no-index\', \'--find-links\', \'/tmp/tmpklvy9437\', \'--root\', \'/\', \'--upgrade\', \'pip\']\nrunpy.run_module("pip", run_name="__main__", alter_sys=True)\n']' returned non-zero exit status 2. **** Installation failed. Aborting package creation. Cleaning up...OK Bye.
解决方法
报错根源是Python 3.12的ensurepip模块在checkinstall的安装环境中出现路径解析错误,导致pip安装失败。以下是两种可行方案:
方案1:配置时跳过ensurepip
修改configure命令,添加--without-ensurepip参数,直接跳过内置pip的安装:
./configure --enable-optimizations --enable-shared --prefix=/usr --without-ensurepip make -j $(nproc) make -n altinstall > make_altinstall.sh chmod +x make_altinstall.sh sudo checkinstall -D ./make_altinstall.sh
制作完成并安装deb包后,手动安装pip:
wget https://bootstrap.pypa.io/get-pip.py sudo python3.12 get-pip.py rm get-pip.py
方案2:修改安装脚本跳过ensurepip
如果不想重新configure,直接编辑生成的make_altinstall.sh,找到所有包含ensurepip的行,在前面添加#注释掉,例如:
# ./python -m ensurepip --altinstall --root="/"
保存后再执行sudo checkinstall -D ./make_altinstall.sh,后续同样手动安装pip。
内容的提问来源于stack exchange,提问作者tompi
相关产品推荐
相关产品推荐

