Skip to content

Py_InitializeFromConfig() does not set module_search_paths or module_search_paths_set #122963

@SwooshyCueb

Description

@SwooshyCueb

Bug report

Bug description:

The documentation for PyConfig.module_search_paths_set states:

If module_search_paths_set is equal to 0, Py_InitializeFromConfig() will replace module_search_paths and sets module_search_paths_set to 1.

However, this doesn't seem to be the case. Given the sample program below, py_config has the same values for module_search_paths and module_search_paths_set before and after the call to Py_InitializeFromConfig:

#include <fmt/format.h>
#include <fmt/xchar.h>

#include <Python.h>

const bool isolated_config = false;

int main(int argc, char* argv[]) {
	PyStatus py_status;
	PyConfig py_config;

	if (isolated_config) {
		PyConfig_InitIsolatedConfig(&py_config);
	}
	else {
		PyConfig_InitPythonConfig(&py_config);
	}

	py_status = Py_InitializeFromConfig(&py_config);
	if (PyStatus_Exception(py_status)) {
		fmt::println("Failed to initialize Python interpreter with status [{0}]: {1}", py_status.exitcode, py_status.err_msg);
		return -1;
	}

	for (Py_ssize_t i = 0; i < py_config.module_search_paths.length; ++i) {
		fmt::println(fmt::runtime(py_config.module_search_paths.items[i]));
	}

	return 0;
}

CPython versions tested on:

3.8, 3.9, 3.10, 3.11, 3.12

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions