Author vstinner
Recipients christian.heimes, houjingyi233, paul.moore, steve.dower, tim.golden, vstinner, zach.ware
Date 2021-01-12.09:59:55
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1610445595.4.0.0630744780603.issue42902@roundup.psfhosted.org>
In-reply-to
Content
The reference documentation for the Python Path Configuration can be found at:
https://docs.python.org/dev/c-api/init_config.html#python-path-configuration

Currently, Py_SetPath(path) indirectly sets the following PyConfig members:

* prefix = ""
* exec_prefix = ""
* module_search_paths = 'path' parameter, string split at DELIM delimiter (";" character on Windows)
* module_search_paths_set = 1

If you want to get the current Python Path Configuration, you can use:
---
import _testinternalcapi
import pprint
pprint.pprint(_testinternalcapi.get_configs())
---

Example with Python 3.10 (extract):
---
{'config': {...
            'argv': ['x.py'],
            ...
            'base_exec_prefix': '/usr/local',
            'base_executable': '/home/vstinner/python/master/python',
            'base_prefix': '/usr/local',
            ...
            'exec_prefix': '/usr/local',
            'executable': '/home/vstinner/python/master/python',
            ...
            'home': None,
            ...
            'module_search_paths': ['/usr/local/lib/python310.zip',
                                    '/home/vstinner/python/master/Lib',
                                    '/home/vstinner/python/master/build/lib.linux-x86_64-3.10-pydebug'],
            'module_search_paths_set': 1,
            ...
            'orig_argv': ['./python', 'x.py'],
            'parse_argv': 2,
            ...
            'pathconfig_warnings': 1,
            'platlibdir': 'lib',
            'prefix': '/usr/local',
            'program_name': './python',
            ...},
 ...,
 'path_config': {'exec_prefix': '/usr/local',
                 'home': None,
                 'module_search_path': '/usr/local/lib/python310.zip:/home/vstinner/python/master/Lib:/home/vstinner/python/master/build/lib.linux-x86_64-3.10-pydebug',
                 'prefix': '/usr/local',
                 'program_full_path': '/home/vstinner/python/master/python',
                 'program_name': './python'},
 ...}
---

See also bpo-42260: "[C API] Add PyInterpreterState_SetConfig(): reconfigure an interpreter" which aims to rewrite the code to configure the Python Path Configuration from C to Python.
History
Date User Action Args
2021-01-12 09:59:55vstinnersetrecipients: + vstinner, paul.moore, christian.heimes, tim.golden, zach.ware, steve.dower, houjingyi233
2021-01-12 09:59:55vstinnersetmessageid: <1610445595.4.0.0630744780603.issue42902@roundup.psfhosted.org>
2021-01-12 09:59:55vstinnerlinkissue42902 messages
2021-01-12 09:59:55vstinnercreate