@@ -266,9 +266,39 @@ def pip_install_reqs(self, reqs_to_install):
266266 )
267267
268268 def python_command (self ):
269- # python is normally found at sys.executable, but there is an issue on windows qgis so use 'python' instead
270- # https://github.com/qgis/QGIS/issues/45646
271- return "python" if os .name == "nt" else sys .executable
269+ if os .path .exists (os .path .join (sys .prefix , "conda-meta" )): # Conda
270+ log ("Attempt Conda install at 'python' shortcut" )
271+ return "python"
272+
273+ # python is normally found at sys.executable, but there is an issue on windows qgis so use 'python' instead: https://github.com/qgis/QGIS/issues/45646
274+ # 'python' doesnt seem to work, using this method instead
275+ if platform .system () == "Windows" : # Windows
276+ base_path = sys .prefix
277+ for file in ["python.exe" , "python3.exe" ]:
278+ path = os .path .join (base_path , file )
279+ if os .path .isfile (path ):
280+ log (f"Attempt Windows install at { str (path )} " )
281+ return path
282+ path = sys .executable
283+ log (f"Attempt Windows install at { str (path )} " )
284+ return path
285+
286+ # Same bug on mac as windows: https://github.com/opengisch/qpip/issues/34#issuecomment-2995221985
287+ if platform .system () == "Darwin" : # Mac
288+ base_path = os .path .join (sys .prefix , "bin" )
289+ for file in ["python" , "python3" ]:
290+ path = os .path .join (base_path , file )
291+ if os .path .isfile (path ):
292+ log (f"Attempt MacOS install at { str (path )} " )
293+ return path
294+ path = sys .executable
295+ log (f"Attempt MacOS install at { str (path )} " )
296+ return path
297+
298+ else : # Fallback attempt
299+ path = sys .executable
300+ log (f"Attempt fallback install at { str (path )} " )
301+ return path
272302
273303 def check (self ):
274304 dialog , _ = self .check_deps ()
0 commit comments