1

From the official example, I understand that I can modify sys.path before the interpreter initializes using the following code(exception handlings are omitted):

PyConfig config;
PyConfig_InitPythonConfig(&config);
PyConfig_Read(&config);
config.module_search_paths_set = 1;
PyWideStringList_Append(&config.module_search_paths, L"/path/to/module");
Py_InitializeFromConfig(&config);

However, as indicated in the document, starting from python 3.11, PyConfig_Read will not initialize path-related fields in PyConfig. My question is: How can I get the default sys.path before the interpreter initializes? I need this because I want to set module_search_paths in the config and normally I would like to append the path for my custom modules to the default sys.path.

I know that I can set sys.path after initializing the interpreter, but I hope I can do it before the initialization.

1
  • How about adding paths to PYTHONPATH? Commented Feb 7, 2024 at 22:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.