Skip to content

Commit

Permalink
Python venv support added
Browse files Browse the repository at this point in the history
Found by: simple
Patch by: thommey
  • Loading branch information
thommey authored Jul 12, 2024
1 parent d2f93d5 commit a49c225
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/mod/python.mod/python.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,23 @@ static int python_gil_lock() {
}

static char *init_python() {
const char *venv;
char venvpython[PATH_MAX];
PyObject *pmodule;
PyStatus status;
PyConfig config;

PyConfig_InitPythonConfig(&config);
config.install_signal_handlers = 0;
config.parse_argv = 0;
if ((venv = getenv("VIRTUAL_ENV"))) {
snprintf(venvpython, sizeof venvpython, "%s/bin/python3", venv);
status = PyConfig_SetBytesString(&config, &config.executable, venvpython);
if (PyStatus_Exception(status)) {
PyConfig_Clear(&config);
return "Python: Fatal error: Could not set venv executable";
}
}
status = PyConfig_SetBytesString(&config, &config.program_name, argv0);
if (PyStatus_Exception(status)) {
PyConfig_Clear(&config);
Expand Down

0 comments on commit a49c225

Please sign in to comment.