From f2d5858d0cd771cd15a25f579d4a400c6548d239 Mon Sep 17 00:00:00 2001 From: yuruo Date: Thu, 20 Mar 2025 10:19:25 +0800 Subject: [PATCH] update china mirror --- install.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/install.py b/install.py index 71fd07c..1ee2da0 100644 --- a/install.py +++ b/install.py @@ -1,9 +1,24 @@ import subprocess import sys from util import download_weights +import urllib.request +import urllib.error def install_requirements(): - subprocess.run([sys.executable, '-m', 'pip', 'install', '-r', 'requirements.txt']) + # Check if Google is accessible + try: + # Try to connect to Google with a timeout of 3 seconds + urllib.request.urlopen('https://www.google.com', timeout=3) + # If successful, install normally + subprocess.run([sys.executable, '-m', 'pip', 'install', '-r', 'requirements.txt']) + except (urllib.error.URLError, TimeoutError): + print("Using Tsinghua mirror") + subprocess.run([ + sys.executable, '-m', 'pip', 'install', + '-r', 'requirements.txt', + '-i', 'https://pypi.tuna.tsinghua.edu.cn/simple' + ]) + def adjust_python_env(): # check if python is 3.12