-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinstall.py
101 lines (85 loc) · 2.98 KB
/
install.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import sys
import os
import subprocess
import traceback
def add_current_dir_to_sys_path():
"""添加当前目录到 sys.path"""
current_dir = os.path.dirname(os.path.abspath(__file__))
if current_dir not in sys.path:
sys.path.append(current_dir)
print(f"Added current directory to sys.path: {current_dir}")
def install_packages(python_executable):
"""安装所需的Python包"""
try:
# 定义要安装的包列表
packages = [
"diffusers",
"transformers",
"rembg",
"tqdm",
"omegaconf",
"matplotlib",
"opencv-python",
"imageio",
"jaxtyping",
"einops",
"SentencePiece",
"accelerate",
"trimesh",
"PyMCubes",
"xatlas",
"libigl",
"open3d"
]
# 定义需要从GitHub安装的包
git_packages = [
"git+https://github.com/facebookresearch/pytorch3d",
"git+https://github.com/NVlabs/nvdiffrast"
]
# 安装普通包
for package in packages:
print(f"Installing {package}...")
subprocess.check_call([
python_executable, "-m", "pip", "install", package,
])
# 安装GitHub上的包
for git_package in git_packages:
print(f"Installing {git_package}...")
subprocess.check_call([
python_executable, "-m", "pip", "install", git_package
])
print("所有依赖项已成功安装。")
except subprocess.CalledProcessError as e:
print(f"安装包时出错: {e}")
raise
def add_installed_packages_to_sys_path(python_executable):
"""将pip安装的包目录添加到sys.path"""
try:
# 获取site-packages路径
import site
site_packages = site.getsitepackages()
user_site = site.getusersitepackages()
all_paths = site_packages + [user_site]
for path in all_paths:
if path and os.path.isdir(path) and path not in sys.path:
sys.path.append(path)
print(f"Added to sys.path: {path}")
except Exception as e:
print(f"添加安装目录到 sys.path 时出错: {e}")
raise
def main():
try:
# 添加当前目录到 sys.path
add_current_dir_to_sys_path()
# 获取当前Python解释器路径
python_executable = sys.executable
print(f"使用的Python解释器: {python_executable}")
# 安装依赖包
install_packages(python_executable)
# 将安装的包目录添加到 sys.path
add_installed_packages_to_sys_path(python_executable)
except Exception as e:
print("安装过程失败,请检查错误信息。")
traceback.print_exc()
if __name__ == "__main__":
main()