@@ -236,40 +236,32 @@ bool PythonWorker::init() {
236236 qputenv (" PYTHONHOME" , python_home.toUtf8 ());
237237
238238#ifdef _WIN32
239- // Python 3.8+ requires explicit DLL directory registration
240- // PATH environment variable is no longer used for DLL search
241- SetDefaultDllDirectories (LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_LIBRARY_SEARCH_USER_DIRS);
242-
243239 if (using_bundled) {
244- // Register bundled Python DLL directories via AddDllDirectory
240+ // Prepend Python DLL directories to PATH so the embedded interpreter can
241+ // find .pyd extension dependencies (e.g. _ctypes.pyd -> libffi-8.dll).
242+ // We use PATH instead of SetDefaultDllDirectories/AddDllDirectory because
243+ // those restrict DLL search process-wide, which breaks the build tree
244+ // where DLLs are spread across conda, deps, and build directories.
245245 QString dlls_dir = python_home + " /DLLs" ;
246- AddDllDirectory (dlls_dir.toStdWString ().c_str ());
247- AddDllDirectory (python_home.toStdWString ().c_str ());
248-
249- // Also add the directory containing the executable (for dependency DLLs)
250246 QString app_dir = QCoreApplication::applicationDirPath ();
251- AddDllDirectory (app_dir.toStdWString ().c_str ());
247+ QString current_path = qgetenv (" PATH" );
248+ QString new_path = dlls_dir + " ;" + python_home + " ;" + app_dir;
252249
253250 // In the build tree, PYTHONHOME points to conda's prefix. Conda's .pyd
254251 // files need DLLs from conda's Library/bin/ (e.g. libexpat.dll for pyexpat).
255252 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,
261- // implicit DLL dependencies of .pyd files (e.g. _ctypes.pyd -> libffi-8.dll)
262- // are not always found via AddDllDirectory alone — PATH is still needed.
263- QString current_path = qgetenv (" PATH" );
264- QString new_path = dlls_dir + " ;" + python_home + " ;" + app_dir;
265253 if (QDir (conda_library_bin).exists ()) {
266254 new_path += " ;" + conda_library_bin;
267255 }
256+
268257 new_path += " ;" + current_path;
269258 qputenv (" PATH" , new_path.toUtf8 ());
270259
271260 SW_LOG (" Registered bundled Python DLL directories" );
272261 } else {
262+ // Legacy conda-based Python path
263+ SetDefaultDllDirectories (LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_LIBRARY_SEARCH_USER_DIRS);
264+
273265 QString home = qgetenv (" USERPROFILE" );
274266 if (python_home.isEmpty ()) {
275267 SW_ERROR (" Unable to initialize Python\n Please run install_shapeworks.bat" );
0 commit comments