Author vstinner
Recipients methane, ncoghlan, pablogsal, steve.dower, vstinner
Date 2019-09-20.16:44:55
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1568997895.56.0.760570797029.issue38236@roundup.psfhosted.org>
In-reply-to
Content
When Python path configuration is not properly configured, Python fails with an error looking like:
---
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 0x00007ff0065b2740 (most recent call first):
<no Python frame>
---

This error is very common and hard to debug. It can happen in various cases for various reasons:

* Python is embedded in an application
* PYTHONPATH and/or PYTHONHOME environment variable is set
* pyenv.cfg configuration for virtual environment
* Local .py files which override the standard library

A few examples:

* bpo-38234: Py_SetPath() regression in Python 3.8 which impacts PyInstaller
* https://bugs.python.org/issue35978#msg335363 virtual env
* https://bugs.python.org/issue35969#msg335249 "encodings.py" file in the current directory
* https://stackoverflow.com/questions/55657593/python-3-8-0a3-failed-to-get-the-python-codec-of-the-filesystem-encoding embedded Python
* https://askubuntu.com/questions/640010/fatal-python-error-py-initialize-unable-to-get-the-locale-encoding-syntaxe Python 3 installed by Anaconda which uses Python 2.7 stdlib because of PYTHONPATH
* https://github.com/GNS3/gns3-gui/issues/2267 Python embedded in "gns3"
* https://github.com/JuliaPy/PyCall.jl/issues/410 venv
* https://techglimpse.com/error-executing-python3-5-command-solution/ another random error

Attached PR dumps the Python path configuration if importing the Python codec of the filesystem encoding fails. In the Python initialization, it's the first import which is done.
History
Date User Action Args
2019-09-20 16:44:55vstinnersetrecipients: + vstinner, ncoghlan, methane, steve.dower, pablogsal
2019-09-20 16:44:55vstinnersetmessageid: <1568997895.56.0.760570797029.issue38236@roundup.psfhosted.org>
2019-09-20 16:44:55vstinnerlinkissue38236 messages
2019-09-20 16:44:55vstinnercreate