-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dump the Python path configuration at the first import error #82417
Comments
When Python path configuration is not properly configured, Python fails with an error looking like: Current thread 0x00007ff0065b2740 (most recent call first): This error is very common and hard to debug. It can happen in various cases for various reasons:
A few examples:
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. |
Without my change: --- Current thread 0x00007fa9c32d6740 (most recent call first): With my PR 16300: --- $ PYTHONHOME=/xxx ./python
Python path configuration:
PYTHONHOME = '/xxx'
PYTHONPATH = '/usr/share/qa-tools/python-modules'
isolated = 0
environment = 1
user site = 1
import site = 1
sys.executable = '/home/vstinner/python/master/python'
sys.prefix = '/xxx'
sys.exec_prefix = '/xxx'
sys.path = [
'/usr/share/qa-tools/python-modules',
'/xxx/lib/python39.zip',
'/xxx/lib/python3.9',
'/xxx/lib/python3.9/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 0x00007f9cef949740 (most recent call first): |
I'm not sure that dumping these configuration variables are useful to debug this very specific error: "Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding" They only have an effect on sys.path later. |
+1 |
I backported my change to Python 3.8. Example with PYTHONPATH set to Python 2.7 with Python 3.8: $ PYTHONPATH=/usr/lib64/python2.7/ ./python -c pass
Python path configuration:
PYTHONHOME = (not set)
PYTHONPATH = '/usr/lib64/python2.7/'
program name = './python'
isolated = 0
environment = 1
user site = 1
import site = 1
sys._base_executable = '/home/vstinner/python/3.8/python'
sys.base_prefix = '/usr/local'
sys.base_exec_prefix = '/usr/local'
sys.executable = '/home/vstinner/python/3.8/python'
sys.prefix = '/usr/local'
sys.exec_prefix = '/usr/local'
sys.path = [
'/usr/lib64/python2.7/',
'/usr/local/lib/python38.zip',
'/home/vstinner/python/3.8/Lib',
'/home/vstinner/python/3.8/build/lib.linux-x86_64-3.8-pydebug',
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
File "/usr/lib64/python2.7/encodings/__init__.py", line 123
raise CodecRegistryError,\
^
SyntaxError: invalid syntax Current thread 0x00007fe3ade4d740 (most recent call first): |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: