1

I just learned, that upon some errors, Python dumps its path configuration ; for instance, like in this snippet from Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding, when trying to start uwsgi :

!!! Python Home is not a directory: /home/env3/educ !!!
Set PythonHome to /home/env3/educ
Python path configuration:
  PYTHONHOME = '/home/env3/educ'
  PYTHONPATH = (not set)
  program name = '/home/env3/educ/bin/python'
  isolated = 0
  environment = 1
  user site = 1
  import site = 1
  sys._base_executable = '/home/env3/educ/bin/python'
  sys.base_prefix = '/home/env3/educ'
  sys.base_exec_prefix = '/home/env3/educ'
  sys.executable = '/home/env3/educ/bin/python'
  sys.prefix = '/home/env3/educ'
  sys.exec_prefix = '/home/env3/educ'
  sys.path = [
    '/home/env3/educ/lib/python38.zip',
    '/home/env3/educ/lib/python3.8',
    '/home/env3/educ/lib/python3.8/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 0x00007efe89db8780 (most recent call first):
<no Python frame>

So, now I'm wondering - is there a command line switch, so I could just call, let's say something like python --dump-path-config, and it would print the above path configuration, and exit?

I am aware that one could write a Python script that would perform the same task and run that - however, since this dump is apparently "built-in" in Python anyways, I was wondering if there was a way to use that machinery.

( Btw, I found Issue 38236: Dump the Python path configuration at the first import error - Python tracker - apparently this kind of dump exists only for Python 3.8 and 3.9 )

sdbbs
  • 4,270
  • 5
  • 32
  • 87

1 Answers1

1

No command line switch for this.

The "Python path configuration" is dumped from: https://github.com/python/cpython/blob/3eb2b9634fdc6826a558fa5aa820dc6e69b7800e/Python/initconfig.c#L3065

but the symbol is not exported to the ctypes.pythonapi and can't be called directly.

You must write a Python script that would perform the same task on other way.

  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/32192855) – jonathan Jul 11 '22 at 20:58