summaryrefslogtreecommitdiffstats
path: root/GUI
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2023-03-08 15:36:46 -0800
committeryum <yum.food.vr@gmail.com>2023-03-08 15:36:46 -0800
commit12b6447a87da8077c7dd12b92eefc27dcf7f0818 (patch)
tree7e04fdfb24ae1fd9e9ae3f754018f3cb54020c40 /GUI
parentb6dc76afb4f76a8b0eaa8f821c557cd83f69daf4 (diff)
Set PYTHONPATH in synchronous multiprocessing layer
A user saw an error like `ModuleNotFoundError: No module named _socket`. StackOverflow blames this on PYTHONPATH, so let's try setting it. * Fix latent bug in Scripts/transcribe.py. PyAudio.open() positional parameters must be specified in correct order, even when telling it which parameter is which. *shrug*
Diffstat (limited to 'GUI')
-rw-r--r--GUI/GUI/GUI/PythonWrapper.cpp34
1 files changed, 29 insertions, 5 deletions
diff --git a/GUI/GUI/GUI/PythonWrapper.cpp b/GUI/GUI/GUI/PythonWrapper.cpp
index 148692a..78947ed 100644
--- a/GUI/GUI/GUI/PythonWrapper.cpp
+++ b/GUI/GUI/GUI/PythonWrapper.cpp
@@ -268,26 +268,50 @@ bool PythonWrapper::InvokeCommandWithArgs(const std::string& cmd,
// Add updated PATH to current process's environment
if (!SetEnvironmentVariableA("PATH", env.c_str())) {
std::ostringstream err_oss;
- err_oss << "Error while executing python command \"" << cmd_oss.str()
- << "\": Failed to add git to PATH: " << GetWin32ErrMsg() << std::endl;
+ err_oss << "Error while executing python command \""
+ << cmd_oss.str()
+ << "\": Failed to add git to PATH: " << GetWin32ErrMsg()
+ << std::endl;
out_cb("", err_oss.str());
return false;
}
}
+
+ // Add python scripts to PATH
std::filesystem::path py_bin = (std::filesystem::current_path() /
- "Resources\Python\Scripts").lexically_normal();
+ "Resources/Python/Scripts").lexically_normal();
if (env.find(py_bin.string()) == std::string::npos) {
env += ";" + py_bin.string();
// Add updated PATH to current process's environment
if (!SetEnvironmentVariableA("PATH", env.c_str())) {
std::ostringstream err_oss;
- err_oss << "Error while executing python command \"" << cmd_oss.str()
- << "\": Failed to add git to PATH: " << GetWin32ErrMsg() << std::endl;
+ err_oss << "Error while executing python command \""
+ << cmd_oss.str()
+ << "\": Failed to add python scripts to PATH: "
+ << GetWin32ErrMsg() << std::endl;
out_cb("", err_oss.str());
return false;
}
}
+
+ // Set up PYTHONPATH
+ std::filesystem::path py_lib = (std::filesystem::current_path() /
+ "Resources/Python/Lib").lexically_normal();
+ std::filesystem::path py_site_pkgs = (std::filesystem::current_path() /
+ "Resources/Python/Lib/site-packages").lexically_normal();
+ std::ostringstream pypath_oss;
+ pypath_oss << py_lib.string();
+ pypath_oss << ';' << py_site_pkgs.string();
+ // Add updated PATH to current process's environment
+ if (!SetEnvironmentVariableA("PYTHONPATH", pypath_oss.str().c_str())) {
+ std::ostringstream err_oss;
+ err_oss << "Error while executing python command \"" << cmd_oss.str()
+ << "\": Failed to add site-packages to PYTHONPATH: "
+ << GetWin32ErrMsg() << std::endl;
+ out_cb("", err_oss.str());
+ return false;
+ }
}
std::string cmd_str = cmd_oss.str();