|
|
@@ -105,7 +105,7 @@ def _download_get_pip(get_pip_path):
|
|
|
except Exception as e:
|
|
|
last_err = e
|
|
|
if last_err:
|
|
|
- print(f"[WARN] 下载 get-pip.py 失败: {last_err}")
|
|
|
+ print(f"[WARN] Failed to download get-pip.py: {last_err}")
|
|
|
return False
|
|
|
|
|
|
|
|
|
@@ -117,7 +117,7 @@ def repair_pip_with_get_pip():
|
|
|
if not _find_or_download_get_pip(get_pip_path):
|
|
|
return False
|
|
|
ok, out, err = run_command(
|
|
|
- f'"{sys.executable}" "{get_pip_path}" --force-reinstall -i {PIP_INDEX_URL} --trusted-host {PIP_TRUSTED_HOST}',
|
|
|
+ f'"{sys.executable}" "{get_pip_path}" --force-reinstall -i {PIP_INDEX_URL} --trusted-host {PIP_TRUSTED_HOST} --no-warn-script-location',
|
|
|
check=False
|
|
|
)
|
|
|
try:
|
|
|
@@ -126,16 +126,16 @@ def repair_pip_with_get_pip():
|
|
|
pass
|
|
|
return ok
|
|
|
except Exception as e:
|
|
|
- print(f"[WARN] 下载/执行 get-pip.py 失败: {e}")
|
|
|
+ print(f"[WARN] Failed to download or run get-pip.py: {e}")
|
|
|
return False
|
|
|
|
|
|
|
|
|
def check_pip():
|
|
|
"""先检测 pip 是否已安装,未安装则退出"""
|
|
|
if not PY_PIP.exists():
|
|
|
- print(f"[X] 缺少 pip。请将 pip.exe 放入: {PY_SCRIPTS}")
|
|
|
+ print(f"[X] pip is missing. Put pip.exe in: {PY_SCRIPTS}")
|
|
|
sys.exit(1)
|
|
|
- print("[OK] pip 已就绪")
|
|
|
+ print("[OK] pip is ready")
|
|
|
|
|
|
|
|
|
def _venv_home():
|
|
|
@@ -180,14 +180,14 @@ def ensure_venv():
|
|
|
venv_cmd = f'"{PY_VIRTUALENV}" "{VENV_PATH}"'
|
|
|
else:
|
|
|
if not PY_PIP.exists():
|
|
|
- print(f"[X] 缺少: {PY_PIP} 和 {PY_VIRTUALENV},请将 pip 和 virtualenv 放入 py/Scripts/")
|
|
|
+ print(f"[X] Missing: {PY_PIP} and {PY_VIRTUALENV}. Put pip and virtualenv in py/Scripts/")
|
|
|
sys.exit(1)
|
|
|
- print("[WARN] 缺少 venv(无法创建虚拟环境),正在使用 pip 安装 virtualenv...")
|
|
|
- pip_ok, pip_out, pip_err = run_command(f'"{PY_PIP}" install {PIP_INDEX_ARGS} virtualenv', check=False)
|
|
|
+ print("[WARN] venv module is missing. Installing virtualenv with pip...")
|
|
|
+ pip_ok, pip_out, pip_err = run_command(f'"{PY_PIP}" install {PIP_INDEX_ARGS} --no-warn-script-location virtualenv', check=False)
|
|
|
if not pip_ok:
|
|
|
- print(f"[X] 安装 virtualenv 失败,缺少: virtualenv。错误: {(pip_err or '') + (pip_out or '')}")
|
|
|
+ print(f"[X] Failed to install virtualenv. Error: {(pip_err or '') + (pip_out or '')}")
|
|
|
sys.exit(1)
|
|
|
- print("[OK] pip 安装 virtualenv 成功")
|
|
|
+ print("[OK] virtualenv installed successfully via pip")
|
|
|
venv_cmd = f'"{PY_VIRTUALENV}" "{VENV_PATH}"' if PY_VIRTUALENV.exists() else f'"{sys.executable}" -m virtualenv "{VENV_PATH}"'
|
|
|
success, out, err = run_command(venv_cmd, check=False)
|
|
|
merged_err = (err or "") + (out or "")
|
|
|
@@ -201,40 +201,40 @@ def ensure_venv():
|
|
|
if VENV_PATH.exists():
|
|
|
try:
|
|
|
shutil.rmtree(VENV_PATH)
|
|
|
- print("[OK] 已删除原虚拟环境目录,将重新创建")
|
|
|
+ print("[OK] Old virtual environment removed, recreating...")
|
|
|
except Exception as e:
|
|
|
- print(f"[WARN] 删除 env 失败: {e}")
|
|
|
- print("[WARN] virtualenv 异常,正在重装 virtualenv...")
|
|
|
+ print(f"[WARN] Failed to remove env: {e}")
|
|
|
+ print("[WARN] virtualenv is broken, reinstalling virtualenv...")
|
|
|
reinstall_ok, _, reinstall_err = run_command(
|
|
|
- f'"{sys.executable}" -m pip install {PIP_INDEX_ARGS} --force-reinstall virtualenv',
|
|
|
+ f'"{sys.executable}" -m pip install {PIP_INDEX_ARGS} --no-warn-script-location --force-reinstall virtualenv',
|
|
|
check=False
|
|
|
)
|
|
|
# pip 自身损坏(如缺少 pip._internal.operations.build)时用 get-pip.py 重装(不依赖残缺 pip,优先国内源)
|
|
|
if not reinstall_ok and ("pip._internal" in (reinstall_err or "") or "ModuleNotFoundError" in (reinstall_err or "")):
|
|
|
- print("[WARN] pip 异常(嵌入式 pip 可能不完整),正在用 get-pip.py 重装 pip(优先国内源)...")
|
|
|
+ print("[WARN] pip is broken (embedded pip may be incomplete), reinstalling pip with get-pip.py...")
|
|
|
if repair_pip_with_get_pip():
|
|
|
reinstall_ok, _, reinstall_err = run_command(
|
|
|
- f'"{sys.executable}" -m pip install {PIP_INDEX_ARGS} --force-reinstall virtualenv',
|
|
|
+ f'"{sys.executable}" -m pip install {PIP_INDEX_ARGS} --no-warn-script-location --force-reinstall virtualenv',
|
|
|
check=False
|
|
|
)
|
|
|
if not reinstall_ok:
|
|
|
ensure_ok, _, _ = run_command(f'"{sys.executable}" -m ensurepip --upgrade', check=False)
|
|
|
if ensure_ok:
|
|
|
reinstall_ok, _, reinstall_err = run_command(
|
|
|
- f'"{sys.executable}" -m pip install {PIP_INDEX_ARGS} --force-reinstall virtualenv',
|
|
|
+ f'"{sys.executable}" -m pip install {PIP_INDEX_ARGS} --no-warn-script-location --force-reinstall virtualenv',
|
|
|
check=False
|
|
|
)
|
|
|
if not reinstall_ok:
|
|
|
- print(f"[X] 重装 virtualenv 失败: {reinstall_err or '(no output)'}")
|
|
|
- print("[HINT] 嵌入式 python/x64/py 内 pip 不完整(缺 pip._internal.operations.build)。")
|
|
|
- print(" 方式一:把 get-pip.py 放到 python/x64/ 或项目根目录,再重新运行本脚本(会优先用本地文件)。")
|
|
|
- print(" 方式二:手动执行(国内下载 get-pip.py: http://mirrors.aliyun.com/pypi/get-pip.py ):")
|
|
|
+ print(f"[X] Failed to reinstall virtualenv: {reinstall_err or '(no output)'}")
|
|
|
+ print("[HINT] Embedded pip in python/x64/py may be incomplete (missing pip._internal.operations.build).")
|
|
|
+ print(" Option 1: put get-pip.py in python/x64/ or project root, then rerun this script (local file is preferred).")
|
|
|
+ print(" Option 2: run manually (download get-pip.py from: http://mirrors.aliyun.com/pypi/get-pip.py):")
|
|
|
print(" python get-pip.py --force-reinstall -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn")
|
|
|
sys.exit(1)
|
|
|
if not reinstall_ok:
|
|
|
- print(f"[X] 重装 virtualenv 失败: {reinstall_err or '(no output)'}")
|
|
|
+ print(f"[X] Failed to reinstall virtualenv: {reinstall_err or '(no output)'}")
|
|
|
sys.exit(1)
|
|
|
- print("[OK] virtualenv 重装完成")
|
|
|
+ print("[OK] virtualenv reinstalled")
|
|
|
# 重新创建虚拟环境:优先 -m venv,再 fallback 到 virtualenv
|
|
|
success, out, err = run_command(f'"{sys.executable}" -m venv "{VENV_PATH}"', check=False)
|
|
|
merged_err = (err or "") + (out or "")
|
|
|
@@ -247,9 +247,9 @@ def ensure_venv():
|
|
|
err_msg = merged_err.strip() or '(no error output)'
|
|
|
print(f"[X] Failed to create virtual environment: {err_msg}")
|
|
|
if "No discovery plugin found" in err_msg:
|
|
|
- print("[HINT] virtualenv dist-info 缺少 entry_points.txt,请检查 virtualenv-*.dist-info/")
|
|
|
+ print("[HINT] virtualenv dist-info is missing entry_points.txt. Check virtualenv-*.dist-info/")
|
|
|
if "pythonw.exe" in err_msg or "FileNotFoundError" in err_msg:
|
|
|
- print("[HINT] 需要 py/pythonw.exe,可从 python.exe 复制")
|
|
|
+ print("[HINT] py/pythonw.exe is required. You can copy it from python.exe.")
|
|
|
sys.exit(1)
|
|
|
print("[OK] Virtual environment created successfully")
|
|
|
return True
|
|
|
@@ -347,13 +347,13 @@ def install_packages(packages, source_file, venv_pip):
|
|
|
total = len(packages)
|
|
|
for i, package in enumerate(packages, 1):
|
|
|
pkg_display = package.split("==")[0].strip() if "==" in package else package.strip()
|
|
|
- print(f"[{i}/{total}] 正在安装 {pkg_display} ...", end=" ", flush=True)
|
|
|
- cmd = f'"{venv_pip}" install {PIP_INDEX_ARGS} {package}'
|
|
|
+ print(f"[{i}/{total}] Installing {pkg_display} ...", end=" ", flush=True)
|
|
|
+ cmd = f'"{venv_pip}" install {PIP_INDEX_ARGS} --no-warn-script-location {package}'
|
|
|
success, _, error = run_command(cmd, check=False)
|
|
|
if success:
|
|
|
print("OK")
|
|
|
else:
|
|
|
- print("失败")
|
|
|
+ print("FAILED")
|
|
|
failed_packages.append(package)
|
|
|
if failed_packages:
|
|
|
return False, failed_packages
|