Python may startup fails if the `home` variable in `pyvenv.cfg` is inaccurate
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Bug report
Bug description:
The problem comes from getpath.py. When getpath.py cannot find STDLIB_LANDMARKS from executable_dir, it will set prefix to the PREFIX. If the directory set in PREFIX does not exist, an error occurs.
See details: https://github.com/python/cpython/blob/49f15d8667e4755876698a8daa13bab6acee5fa1/Modules/getpath.py#L590-L599
How to reproduce
# 1. build cpython with prefix
./configure --prefix=/home/xx/tmp/install_dir
make
make install
# 2. copy install_dir to another
cd /home/xx/tmp
cp -r ./install_dir/ ./copy_dir
# 3. create a symlink from copy_dir/python
ln -s ./copy_dir/bin/python3 ./pylink
# 4. delete original install_dir
rm -rf ./install_dir/
# 5. use python symlink to create a venv
./pylink -m venv ./bad_venv
# 6. failed to start!
./bad_venv/bin/python3
Error message
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Python path configuration:
PYTHONHOME = (not set)
PYTHONPATH = (not set)
program name = './bad_venv/bin/python3'
isolated = 0
environment = 1
user site = 1
safe_path = 0
import site = 1
is in build tree = 0
stdlib dir = '/home/xx/tmp/install_dir/lib/python3.12'
sys._base_executable = '/home/xx/tmp/copy_dir/bin/python3.12'
sys.base_prefix = '/home/xx/tmp/install_dir'
sys.base_exec_prefix = '/home/xx/tmp/install_dir'
sys.platlibdir = 'lib'
sys.executable = '/home/xx/tmp/bad_venv/bin/python3'
sys.prefix = '/home/xx/tmp/install_dir'
sys.exec_prefix = '/home/xx/tmp/install_dir'
sys.path = [
'/home/xx/tmp/install_dir/lib/python312.zip',
'/home/xx/tmp/install_dir/lib/python3.12',
'/home/xx/tmp/install_dir/lib/python3.12/lib-dynload',
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'
We can find that sys._base_executable here is correct, but sys.base_prefix is wrong.
We could configure base_prefix through the real interpreter path, which is used to search for libraries that Python depends on.
CPython versions tested on:
3.12
Operating systems tested on:
Linux
Linked PRs
- gh-127441
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
先从 Modules/getpath.py 第 590-599 行附近开始,然后在 Linux 上运行已报告的 build、复制、symlink 和 venv 重现步骤。比较得到的 sys._base_executable 和 sys.base_prefix 值,并查看相关 PR gh-127441。当迁移后的 venv 解释器能够启动并加载 encodings,且不引用已删除的安装路径时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- operating-systems
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100