Skip to content

Commit aafc367

Browse files
committed
Fix build-tree DLL search: add conda Library/bin for pyexpat and other extensions
1 parent 1c959c5 commit aafc367

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

Libs/Application/Job/PythonWorker.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,26 @@ bool PythonWorker::init() {
246246
AddDllDirectory(dlls_dir.toStdWString().c_str());
247247
AddDllDirectory(python_home.toStdWString().c_str());
248248

249-
// Also add the directory containing ShapeWorksStudio.exe (for dependency DLLs)
249+
// Also add the directory containing the executable (for dependency DLLs)
250250
QString app_dir = QCoreApplication::applicationDirPath();
251251
AddDllDirectory(app_dir.toStdWString().c_str());
252252

253-
// Also prepend DLLs/ and python home to PATH. In the embedded interpreter,
253+
// In the build tree, PYTHONHOME points to conda's prefix. Conda's .pyd
254+
// files need DLLs from conda's Library/bin/ (e.g. libexpat.dll for pyexpat).
255+
QString conda_library_bin = python_home + "/Library/bin";
256+
if (QDir(conda_library_bin).exists()) {
257+
AddDllDirectory(conda_library_bin.toStdWString().c_str());
258+
}
259+
260+
// Prepend DLL directories to PATH as well. In the embedded interpreter,
254261
// implicit DLL dependencies of .pyd files (e.g. _ctypes.pyd -> libffi-8.dll)
255-
// are not found via AddDllDirectory alone — PATH is still needed.
262+
// are not always found via AddDllDirectory alone — PATH is still needed.
256263
QString current_path = qgetenv("PATH");
257-
QString new_path = dlls_dir + ";" + python_home + ";" + app_dir + ";" + current_path;
264+
QString new_path = dlls_dir + ";" + python_home + ";" + app_dir;
265+
if (QDir(conda_library_bin).exists()) {
266+
new_path += ";" + conda_library_bin;
267+
}
268+
new_path += ";" + current_path;
258269
qputenv("PATH", new_path.toUtf8());
259270

260271
SW_LOG("Registered bundled Python DLL directories");

0 commit comments

Comments
 (0)