@@ -178,6 +178,26 @@ def report(msg):
178178 report ("CUDA installation complete. Please restart Buzz to enable GPU acceleration." )
179179
180180
181+ def _ensure_pip (python : str ) -> list [str ]:
182+ """Return [python, '-m', 'pip'], bootstrapping pip via ensurepip if needed."""
183+ hide_kwargs = _subprocess_hide_window_kwargs ()
184+ pip_cmd = [python , "-m" , "pip" ]
185+ probe = subprocess .run (pip_cmd + ["--version" ], capture_output = True , timeout = 15 , ** hide_kwargs )
186+ if probe .returncode == 0 :
187+ return pip_cmd
188+ logger .info ("pip not found for %s, bootstrapping via ensurepip..." , python )
189+ bootstrap = subprocess .run (
190+ [python , "-m" , "ensurepip" , "--upgrade" ],
191+ capture_output = True , timeout = 60 , ** hide_kwargs ,
192+ )
193+ if bootstrap .returncode != 0 :
194+ raise RuntimeError (
195+ f"pip is not available for { python } and ensurepip failed. "
196+ "Please install pip manually and try again."
197+ )
198+ return pip_cmd
199+
200+
181201def _get_pip_cmd () -> list [str ]:
182202 """Return a [python, '-m', 'pip'] command that is guaranteed to work.
183203
@@ -198,38 +218,18 @@ def _get_pip_cmd() -> list[str]:
198218 python_name = "python.exe" if sys .platform == "win32" else "python3"
199219 bundled_python = internal_dir / "python" / python_name
200220 if bundled_python .is_file ():
201- return [ str (bundled_python ), "-m" , "pip" ]
221+ return _ensure_pip ( str (bundled_python ))
202222 # Fallback: look in PATH
203223 for candidate in ("python3.12" , "python3" , "python" ):
204224 python = shutil .which (candidate )
205225 if python :
206- return [ python , "-m" , "pip" ]
226+ return _ensure_pip ( python )
207227 raise RuntimeError (
208228 "Could not find a Python interpreter. "
209229 "Please install Python 3.12 and try again."
210230 )
211231
212- pip_cmd = [sys .executable , "-m" , "pip" ]
213- hide_kwargs = _subprocess_hide_window_kwargs ()
214-
215- # Check if pip is already available
216- probe = subprocess .run (pip_cmd + ["--version" ], capture_output = True , timeout = 15 , ** hide_kwargs )
217- if probe .returncode == 0 :
218- return pip_cmd
219-
220- # Try to bootstrap pip via ensurepip (available in CPython stdlib)
221- logger .info ("pip not found, bootstrapping via ensurepip..." )
222- bootstrap = subprocess .run (
223- [sys .executable , "-m" , "ensurepip" , "--upgrade" ],
224- capture_output = True , timeout = 60 , ** hide_kwargs ,
225- )
226- if bootstrap .returncode != 0 :
227- raise RuntimeError (
228- "pip is not available and ensurepip failed. "
229- "Please install pip manually and try again."
230- )
231-
232- return pip_cmd
232+ return _ensure_pip (sys .executable )
233233
234234
235235def _subprocess_hide_window_kwargs () -> dict [str , Any ]:
0 commit comments