forked from Heath-AFM-Lab/pNanoLocz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_requirements.py
46 lines (39 loc) · 1.64 KB
/
install_requirements.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
import subprocess
import sys
import os
def install_with_conda(package):
"""Attempt to install a package with conda."""
try:
subprocess.check_call(['conda', 'install', '--yes', package, '-c', 'conda-forge', "-c", "pytorch", "-c", "nvidia"])
print(f'Successfully installed {package} with conda')
except subprocess.CalledProcessError:
print(f'Failed to install {package} with conda, falling back to pip')
return False
return True
def install_with_pip(package):
"""Install a package with pip."""
try:
subprocess.check_call([sys.executable, '-m', 'pip', 'install', package])
print(f'Successfully installed {package} with pip')
except subprocess.CalledProcessError as e:
print(f'Failed to install {package} with pip: {e}')
def main(requirements_file):
if not os.path.isfile(requirements_file):
print(f'Error: {requirements_file} does not exist.')
return
is_macos = sys.platform == 'darwin'
with open(requirements_file, 'r') as f:
for line in f:
package = line.strip()
if package and not package.startswith('#'):
if is_macos and ('cuda' or "cupy") in package.lower():
print(f'Skipping {package} installation on macOS.')
continue
print(f'Installing {package}...')
if package.lower().startswith('pyqt6'):
install_with_pip(package)
else:
if not install_with_conda(package):
install_with_pip(package)
if __name__ == '__main__':
main("requirements.txt")