-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibraryChecker.py
More file actions
47 lines (33 loc) · 1.4 KB
/
LibraryChecker.py
File metadata and controls
47 lines (33 loc) · 1.4 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
import importlib.util
import os
import nltk
class LibraryChecker:
def __init__(self):
self.libraries = []
if os.path.exists("requirements.txt"):
with open("requirements.txt", "r") as required_libraries_reader:
self.libraries.extend(required_libraries_reader)
else:
print("No requirements.txt file found")
self.libraries = []
self.check_libraries()
self.download_nltk()
def check_libraries (self):
missing_libraries = []
for lib in self.libraries:
if importlib.util.find_spec(lib) is None:
missing_libraries.append(lib)
if missing_libraries:
print("Libraries missing, please install it: {}".format(missing_libraries))
os.system("pip install -r requirements.txt")
else:
print("All libraries are installed. we are starting elias")
#Downloading Nltk-Model (German and English)
def download_nltk(self):
nltk_data_path = "./nltk_data/tokenizers/punkt/PY3/"
if not os.path.exists(os.path.join(nltk_data_path, "english.pickle")):
print("English tokenizer missing. Downloading...")
nltk.download('punkt_tab')
if not os.path.exists(os.path.join(nltk_data_path, "german.pickle")):
print("German tokenizer missing. Downloading...")
nltk.download('punkt')