python / python/cpython

3.11 Regression, Py_Initialize; Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding

未關閉
#99,004 7 則留言 2 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

3.11 OS-windows type-bug
主要語言
Python
星號
77.2k
分支
36k
平均合併
1 天 9 小時
30 天內合併 PR
558

描述

Bug report

Build and run the following program;

  #include <Python.h>
  
  int main(int argc, char* argv[])
  {
    Py_Initialize();
    return 0;
  }

The resulting executable runs fine when executed against the installed C:\Program Files\Python311\python311.dll

Executing against python311.dll copied to some other folder (C:\Windows\System32 for instance) results in;

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'

Current thread 0x0000333c (most recent call first):
  <no Python frame>

When also C:\Program Files\Python311\Lib\encodings is copied then the executable runs fine again.

This is not the case with Python versions prior to 3.11. The only thing needed to run Python embedded for versions below 3.11 is the appropriate pythonXXX.dll

Your environment

  • CPython versions tested on:
    Python 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)] on win32
  • Operating system and architecture:
    Edition Windows 11 Pro
    Version 21H2
    Installed on ‎11/‎24/‎2021
    OS build 22000.1098
    Experience Windows Feature Experience Pack 1000.22000.1098.0
  • Compiler used:
    Microsoft Visual Studio Community 2022
    Version 17.3.6
    VisualStudio.17.Release/17.3.6+32929.385
    Microsoft .NET Framework
    Version 4.8.04161
    Installed Version: Community
    Visual C++ 2022 00482-90000-00000-AA258
    Microsoft Visual C++ 2022

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從使用 Py_Initialize 和 Python.h 的 C 程式開始,在 Windows 11 上使用 Python 3.11 重現該行為。比較使用已安裝的 python311.dll、複製的 DLL 以及較早 Python 版本時的執行結果,接著調查初始化如何定位 Lib/encodings。當複製的 Python 3.11 DLL 無需另外複製 encodings 目錄即可完成初始化時,即視為完成。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
c, python
領域
api, operating-systems
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。