3.11 no longer builds with a configured empty prefix
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 35/100
- Issue 類型
- 缺陷
- 描述清晰度
- 基本清楚
- 活躍度
- 停滯
- 領域
- build-system
研究方向
使用 ./configure --prefix= 後執行 make 重現失敗,然後追蹤 Modules/getpath.py、Modules/getpath.c、Python/initconfig.c 和 Python/sysmodule.c 中的 prefix 值。將 C 到 Python 的轉換與 issue 中提到的早期行為進行比較。當 CPython 能在空的 prefix 下成功建置,且受影響的 prefix 屬性仍可使用時,即表示完成。
由索引模型根據 Issue 內容生成。
描述
Bug report
In 3.11 is not possible to build by running ./configure with an empty prefix:
./configure --prefix=
After such configuration, running make fails with something similar to the following:
./_bootstrap_python ./Programs/_freeze_module.py abc ./Lib/abc.py Python/frozen_modules/abc.h
Fatal Python error: init_import_site: Failed to import the site module
Python runtime state: initialized
Traceback (most recent call last):
File "/home/etanol/Python-3.11.1/Lib/site.py", line 79, in <module>
PREFIXES = [sys.prefix, sys.exec_prefix]
^^^^^^^^^^
AttributeError: module 'sys' has no attribute 'prefix'
Makefile:1200: recipe for target 'Python/frozen_modules/abc.h' failed
Possible explanation
The sys module takes attributes like sys.exec and sys.exec_prefix from the PyConfig structure. However, if any of those values is NULL, the attribute does not seem to be defined.
During path calculation, the result of evaluating (the frozen version of) getpath.py is copied back to PyConfig. But the prefix and similar fields are treated by converting None to NULL (from the C macro expansion).
The prefix indicated to ./configure is passed on when compiling getpath.c. But empty strings are converted to None. If the evaluation of (frozen) getpath.py assigns None to the prefix global variable (and similar) what gets transferred back to getpath.c ends up becoming NULL in PyConfig.
I think an empty prefix worked in 3.10, and earlier, because the transition from C compiler macro to Python value preserved empty strings. Empty C strings were converted to empty Python strings; but 3.11 converts empty C strings to None.
Considerations
Using dummy values for ./configure --prefix and then controlling installation target with make DESTDIR=... is a fairly common practice when creating binary packages. It's very convenient as a way to build software inside sandboxed environments.
However, it is certainly arguable that allowing for an empty prefix may not be of interest (it's just as common to run ./configure --prefix=/).
It is also beyond my understanding to determine if the fix should be about preserving empty strings in the C to Python conversion or perhaps the logic in getpath.py should be modified with a last resort check to avoid setting prefix (and similar) to None.
Your environment
- CPython versions tested on: 3.11.1
- Operating system and architecture: Ubuntu 18.04 x86-64
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- 平均合併
- 1 天 9 小時
- 30 天內合併 PR
- 558
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
python/cpython 的其他 Issue
-
docs pending
難度 2/5 1-3 小時 新手友好度 78/100
-
stdlib type-feature
難度 2/5 1-3 小時 新手友好度 78/100
-
stdlib type-feature
難度 2/5 1-3 小時 新手友好度 72/100
-
build type-bug
難度 2/5 1-3 小時 新手友好度 76/100
-
stdlib topic-email type-feature
難度 2/5 1-3 小時 新手友好度 70/100
相似的 Issue
-
link-check link-check:sphinx-theme
難度 2/5 1-3 小時 新手友好度 72/100
-
難度 2/5 1-3 小時 新手友好度 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
難度 2/5 1-3 小時 新手友好度 88/100
OpenHands/extensions#626 · 1 則留言 ·
-
難度 1/5 1 小時以內 新手友好度 90/100
CSCfi/sd-search-api#39 ·
-
難度 1/5 1 小時以內 新手友好度 90/100