Python - dump Python路径配置从命令行?



我刚刚了解到,在某些错误时,Python会转储其路径配置;例如,在尝试启动uwsgi:

时,像以下代码片段一样,来自致命Python错误:init_fs_encoding:未能获得文件系统编码的Python编解码器
!!! 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>

那么,现在我想知道-是否有一个命令行开关,这样我就可以调用,比如python --dump-path-config,它会打印上面的路径配置,然后退出?

我知道可以编写一个Python脚本来执行相同的任务并运行它-然而,由于这个转储显然是"内置的";在Python中无论如何,我在想如果有一种方法使用机械。

(顺便说一句,我发现问题38236:转储Python路径配置在第一个导入错误- Python跟踪器-显然这种转储只存在于Python 3.8和3.9)

没有命令行开关。

Python路径配置"转储路径:https://github.com/python/cpython/blob/3eb2b9634fdc6826a558fa5aa820dc6e69b7800e/Python/initconfig.c#L3065

,但符号不导出到ctypes。不能直接调用。

你必须编写一个Python脚本,以其他方式执行相同的任务。