MCPcopy Create free account
hub / github.com/unslothai/unsloth / pip_install_try

Function pip_install_try

studio/install_python_stack.py:1867–1898  ·  view source on GitHub ↗

Like pip_install but returns False on failure instead of exiting. For optional installs that have a follow-up fallback.

(
    label: str,
    *args: str,
    constrain: bool = True,
    force_pip: bool = False,
)

Source from the content-addressed store, hash-verified

1865
1866
1867def pip_install_try(
1868 label: str,
1869 *args: str,
1870 constrain: bool = True,
1871 force_pip: bool = False,
1872) -> bool:
1873 """Like pip_install but returns False on failure instead of exiting.
1874 For optional installs that have a follow-up fallback.
1875 """
1876 constraint_args_pip: list[str] = []
1877 constraint_args_uv: list[str] = []
1878 if constrain and CONSTRAINTS.is_file():
1879 constraint_args_pip = ["-c", str(CONSTRAINTS)]
1880 constraint_args_uv = ["-c", _uv_safe_path(CONSTRAINTS)]
1881
1882 if USE_UV and not force_pip:
1883 cmd = _build_uv_cmd(args) + constraint_args_uv
1884 else:
1885 cmd = _build_pip_cmd(args) + constraint_args_pip
1886
1887 if VERBOSE:
1888 _step(_LABEL, f"{label}...", _dim)
1889 result = subprocess.run(
1890 cmd,
1891 stdout = subprocess.PIPE,
1892 stderr = subprocess.STDOUT,
1893 )
1894 if result.returncode == 0:
1895 return True
1896 if VERBOSE and result.stdout:
1897 print(result.stdout.decode(errors = "replace"))
1898 return False
1899
1900
1901def pip_install(

Callers 2

_ensure_rocm_torchFunction · 0.85

Calls 5

_build_uv_cmdFunction · 0.85
_build_pip_cmdFunction · 0.85
_stepFunction · 0.85
runMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…