Show a better error message when PYTHONHOME is wrong
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 77.2k
- Forks
- 35.9k
- Métriques de merge des PR
- Métriques de PR en attente
Description
Feature or enhancement
Proposal:
Currently, when PYTHONHOME is wrong, python says ModuleNotFoundError: No module named 'encodings'. This is error makes it sound like a module is missing, when it's actually a part of the core interpreter configuration that is broken, which the error doesn't tell.
Ideally, the error would show if a pyvenv.cfg was loaded, as a wrong home path causes this error.
Example pyenv Python 3.12 on Ubuntu 24.04:
$ PYTHONHOME=/dev/null python
Python path configuration:
PYTHONHOME = '/dev/null'
PYTHONPATH = (not set)
program name = 'python'
isolated = 0
environment = 1
user site = 1
safe_path = 0
import site = 1
is in build tree = 0
stdlib dir = '/dev/null/lib/python3.12'
sys._base_executable = '/home/konsti/.local/bin/python'
sys.base_prefix = '/dev/null'
sys.base_exec_prefix = '/dev/null'
sys.platlibdir = 'lib'
sys.executable = '/home/konsti/.local/bin/python'
sys.prefix = '/dev/null'
sys.exec_prefix = '/dev/null'
sys.path = [
'/dev/null/lib/python312.zip',
'/dev/null/lib/python3.12',
'/dev/null/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'
Current thread 0x00007a7eee702b80 (most recent call first):
<no Python frame>
Example python-build-standalone on Ubuntu 24.04:
$ PYTHONHOME=/dev/null python3.13
Fatal Python error: Failed to import encodings module
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'
Current thread 0x000072ef39049b80 (most recent call first):
<no Python frame>
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
There are several bug reports featuring this error: https://github.com/python/cpython/issues?q=is%3Aissue+%22ModuleNotFoundError%3A+No+module+named+%27encodings%27%22+
https://stackoverflow.com/questions/38132755/importerror-no-module-named-encodings
The error is occurring for users in various communities: https://www.google.com/search?q=%22ModuleNotFoundError%3A+No+module+named+%27encodings%27%22
Linked PRs
- gh-126027
- gh-127616
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par examiner la gestion de PYTHONHOME et de pyvenv.cfg décrite dans l’issue, puis inspectez les PR liés gh-126027 et gh-127616 pour connaître l’orientation actuelle. Reproduisez les exemples avec /dev/null et comparez les diagnostics au démarrage ; le travail est terminé lorsqu’une configuration incorrecte du cœur est clairement identifiée, au lieu de simplement signaler que encodings est manquant.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- operating-systems
- Type d'issue
- Fonctionnalité
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 25/100