mirror of
https://github.com/modelscope/FunASR
synced 2025-09-15 14:48:36 +08:00
utils.install_model_requirements: support installing with uv (#2329)
When using the uv[1] package manager, pip commands need to be proxied through uv's pip compatible interface[2]. Calling pip directly causes a FileNotFoundError. [1] https://docs.astral.sh/uv/ [2] https://docs.astral.sh/uv/pip/packages/
This commit is contained in:
parent
d32e112894
commit
d2cd95bd67
@ -1,15 +1,10 @@
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
|
||||
def install_requirements(requirements_path):
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["pip", "install", "-r", requirements_path],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
text=True,
|
||||
)
|
||||
|
||||
result = pip_install_r(requirements_path)
|
||||
# check status
|
||||
if result.returncode == 0:
|
||||
print("install model requirements successfully")
|
||||
@ -19,13 +14,7 @@ def install_requirements(requirements_path):
|
||||
print("error", result.stderr)
|
||||
return False
|
||||
except Exception as e:
|
||||
result = subprocess.run(
|
||||
["pip", "install", "-r", requirements_path],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
text=True,
|
||||
)
|
||||
|
||||
result = pip_install_r(requirements_path)
|
||||
# check status
|
||||
if result.returncode == 0:
|
||||
print("install model requirements successfully")
|
||||
@ -34,3 +23,20 @@ def install_requirements(requirements_path):
|
||||
print("fail to install model requirements! ")
|
||||
print("error", result.stderr)
|
||||
return False
|
||||
|
||||
|
||||
def pip_install_r(requirements_path):
|
||||
cmd = []
|
||||
if shutil.which("pip") is not None:
|
||||
cmd = ["pip"]
|
||||
elif shutil.which("uv") is not None:
|
||||
cmd = ["uv", "pip"]
|
||||
else:
|
||||
raise RuntimeError("pip not found, failed to install model requirements")
|
||||
cmd += ["install", "-r", requirements_path]
|
||||
return subprocess.run(
|
||||
cmd,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
text=True,
|
||||
)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user