-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
107 lines (88 loc) · 3.03 KB
/
main.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
102
103
104
105
106
107
"""
Auteur : DUTRA Enzo (2021)
"""
import subprocess, os
dependencies = [
"lxml",
"ntpath",
"matplotlib",
"tensorflow",
"tensorboard", # linux : ~/.local/bin/tensorboard ---> http://localhost:6006/ --host --port
#"keras",
"numpy",
"pillow",
"webbrowser",
"traceback",
"trace",
"threading",
"yaml",
"scipy" # il n'y a pas d'import dans le code mais tensorflow en a besoin
]
linux_packages = {
"python3-tk": "tkinter"
}
macos_packages = {
"[email protected]": "tkinter"
}
windows_packages = {
"tkinter": "tkinter"
} # url site si winget ne le contient pas
def import_or_install_os_package(package, py_import):
try:
__import__(py_import)
except (ImportError, ModuleNotFoundError):
if os.name == "posix": # Linux
command = "sudo apt-get install -y " + package
subprocess.check_call(command.split(" "))
elif os.name == "darwin": # MacOS
command = "brew install " + package
try:
subprocess.check_call(command.split(" "))
except:
install_brew = '/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"'
subprocess.check_call(install_brew.split(" "))
subprocess.check_call(command.split(" "))
elif os.name == "windows": # windows
command = "winget install " + package
try:
subprocess.check_call(command.split(" "))
pass
except:
# webbrowser doit etre importé à ce stade là
webbrowser.open(package)
import_or_install_python_package(py_import)
def import_or_install_python_package(package):
try:
__import__(package)
except (ImportError, ModuleNotFoundError):
print("Le module " + package + " n'est pas installé, installation ...")
try:
python = get_python_command()
subprocess.check_call([python, '-m', 'pip', 'install', package]) # install pkg
except:
print(
"Les modules manquants n'ont pas pu etre installés, veuillez vous assurer que tous les modules suivants sont bien présents:")
print(dependencies)
def get_python_command():
try:
subprocess.check_call(["python3", "--version"])
return "python3"
except:
return "python"
# installation des dépendances python
for package in dependencies:
import_or_install_python_package(package)
# installation des packages requis
os_packages = {}
if os.name == "posix": os_packages = linux_packages # Linux
if os.name == "darwin": os_packages = macos_packages # MacOS
if os.name == "windows": os_packages = windows_packages # Windows
for package, py_import in linux_packages.items(): import_or_install_os_package(package, py_import)
# Lancement de la vue
from tkinter import Tk
from view import Interface
fenetre = Tk()
fenetre.title("CNNTrainer")
interface = Interface(fenetre)
interface.mainloop()
interface.destroy()