python / python/cpython

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

Ouverte
#99,004 7 commentaires 2 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

3.11 OS-windows type-bug
Langage dominant
Python
Étoiles
77.2k
Forks
36k
Merge moyen
1 j 9 h
PR mergées (30 j)
558

Description

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

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par le programme C qui utilise Py_Initialize et Python.h, en reproduisant le comportement sous Windows 11 avec Python 3.11. Comparez l’exécution avec la python311.dll installée, une DLL copiée et des versions antérieures de Python, puis étudiez comment l’initialisation localise Lib/encodings. Le travail est terminé lorsque la DLL Python 3.11 copiée peut s’initialiser sans copier séparément le répertoire encodings.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
c, python
Domaine
api, operating-systems
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.