Import errors with loo long entry in sys.path or PYTHONPATH in Windows
未关闭
还没有人认领这个 Issue。
3.12
3.13
3.14
OS-windows
type-bug
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Bug report
Bug description:
Having too long entries in sys.path or PYTHONPATH in Windows will cause different errors in imports. This was first reported on #122170, where there is some useful discussion.
> $Env:PYTHONPATH="a" * 33000
> py -3.13
Exception ignored in running getpath:
Traceback (most recent call last):
File "<frozen getpath>", line 668, in <module>
OSError: failed to make path absolute
Fatal Python error: error evaluating path
Python runtime state: core initialized
Current thread 0x00005a8c (most recent call first):
<no Python frame>
>>> import sys
>>> sys.path.insert(0, "a" * 33000)
>>> import email
Traceback (most recent call last):
File "<frozen importlib._bootstrap_external>", line 1512, in _path_importer_cache
KeyError: 'aaaaaaaaaaaaaaaaaaaaaaaa[...]aaaaaaaaaa'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<python-input-6>", line 1, in <module>
import email
File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
File "<frozen importlib._bootstrap>", line 1322, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1262, in _find_spec
File "<frozen importlib._bootstrap_external>", line 1555, in find_spec
File "<frozen importlib._bootstrap_external>", line 1527, in _get_spec
File "<frozen importlib._bootstrap_external>", line 1514, in _path_importer_cache
File "<frozen importlib._bootstrap_external>", line 1490, in _path_hooks
File "<frozen importlib._bootstrap_external>", line 1714, in path_hook_for_FileFinder
File "<frozen importlib._bootstrap_external>", line 173, in _path_isdir
File "<frozen importlib._bootstrap_external>", line 158, in _path_is_mode_type
File "<frozen importlib._bootstrap_external>", line 152, in _path_stat
ValueError: stat: path too long for Windows
CPython versions tested on:
3.13, CPython main branch
Operating systems tested on:
Windows
Linked PRs
- gh-122389
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 issue 中的长路径复现开始,并检查 Windows 上 frozen getpath 和 importlib._bootstrap_external 的 traceback 位置。查看 issue #122170 和关联的 PR gh-122389,了解现有方向。当较长的 PYTHONPATH 和 sys.path 条目不再产生所报告的启动或导入错误时,即视为完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- backend, operating-systems
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100