-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_req.py
52 lines (33 loc) · 1.63 KB
/
install_req.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
import sys
import subprocess
import pkg_resources # usado para verificar pacotes já instalados no python
class install_missing_pkg:
### https://stackoverflow.com/questions/48097428/how-to-check-and-install-missing-modules-in-python-at-time-of-execution
#https://stackoverflow.com/questions/12332975/installing-python-module-within-code
def __init__(self):
self.main()
def install_required_packages(self, missing_pkg):
subprocess.check_call([sys.executable, '-m', 'pip', 'install', *missing_pkg]) # o * desempacota a lista missing_pkg
def main(self):
install_pkg = True
if install_pkg:
required_pkg_list = {'numpy',
'scipy',
'pandas',
'matplotlib',
'seaborn',
'plotly',
'scikit-learn',
'tensorflow',
'kaleido',
'psutil',
'scikit-image'}
installed = {pkg.key for pkg in pkg_resources.working_set}
missing_pkg = required_pkg_list-installed
if missing_pkg:
print('\nSome packages are not installed yet!!')
print('------------------------------------------\n')
print('Installing...\n')
self.install_required_packages(missing_pkg)
print('\nMissing packages are now installed and ready to use')
print('--------------------------------------------------------\n')