diff --git a/a00_qpip/plugin.py b/a00_qpip/plugin.py index f57c287..7a54311 100644 --- a/a00_qpip/plugin.py +++ b/a00_qpip/plugin.py @@ -266,9 +266,39 @@ def pip_install_reqs(self, reqs_to_install): ) def python_command(self): - # 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 - return "python" if os.name == "nt" else sys.executable + if os.path.exists(os.path.join(sys.prefix, "conda-meta")): # Conda + log("Attempt Conda install at 'python' shortcut") + return "python" + + # 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 + # 'python' doesnt seem to work, using this method instead + if platform.system() == "Windows": # Windows + base_path = sys.prefix + for file in ["python.exe", "python3.exe"]: + path = os.path.join(base_path, file) + if os.path.isfile(path): + log(f"Attempt Windows install at {str(path)}") + return path + path = sys.executable + log(f"Attempt Windows install at {str(path)}") + return path + + # Same bug on mac as windows: https://github.com/opengisch/qpip/issues/34#issuecomment-2995221985 + if platform.system() == "Darwin": # Mac + base_path = os.path.join(sys.prefix, "bin") + for file in ["python", "python3"]: + path = os.path.join(base_path, file) + if os.path.isfile(path): + log(f"Attempt MacOS install at {str(path)}") + return path + path = sys.executable + log(f"Attempt MacOS install at {str(path)}") + return path + + else: # Fallback attempt + path = sys.executable + log(f"Attempt fallback install at {str(path)}") + return path def check(self): dialog, _ = self.check_deps()