-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlibrary_check.py
More file actions
47 lines (37 loc) · 1.11 KB
/
Copy pathlibrary_check.py
File metadata and controls
47 lines (37 loc) · 1.11 KB
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
requirements = {
'torch': 'torch',
'torchvision': 'torchvision',
'albumentations': 'albumentations',
'efficientnet_pytorch': 'efficientnet_pytorch',
'numpy': 'numpy',
'pandas': 'pandas',
'sklearn': 'scikit-learn',
'PIL': 'pillow',
'pydicom': 'pydicom',
'torchinfo': 'torchinfo',
'matplotlib': 'matplotlib',
'seaborn': 'seaborn',
}
def check(raise_exception=False):
import importlib
fallback = []
for key in requirements:
try:
importlib.import_module(key)
except ImportError:
fallback.append(requirements[key])
continue
if fallback:
exc = ImportError("Please install these libraries by pip: %s" % ", ".join(fallback))
if raise_exception:
raise exc
try:
from pip._internal.cli.main import main
for value in fallback:
main(['pip', 'install', value])
check(raise_exception=True)
except Exception as e:
raise exc from e
print("All required libraries are installed.")
if __name__ == '__main__':
check()