1+ import os
12import sys
23import subprocess
3- import os
4-
5- # Vars
6- missingPkgs = 0
74
5+ clear = lambda : os .system ('cls' )
86
9- # Cleaned most of this file,
10- # This file is now working.
11- # Last update 2022,Jan,10
7+ def install (package : str ):
8+ subprocess .check_call ([sys .executable , '-m' , 'pip' , 'install' , package ])
129
13- def setup ():
14- global missingPkgs
15- # Testing imports
10+ def is_installed (package : str ):
1611 try :
17- import pymem
18- print (pymem .__name__ )
12+ __import__ (package )
13+ return True
14+
1915 except ImportError :
20- missingPkgs += 1
16+ return False
17+
18+ except Exception as e :
19+ print (f'Unexpected error: { e } while checking if { package } is installed' )
20+ return True
21+
22+ def get_pending_packages ():
23+ pending = []
24+ with open ('requirements.txt' , 'rt' ) as f :
25+ requirements = f .read ().splitlines ()
26+ for package in requirements :
27+ if package and not is_installed (package ):
28+ pending .append (package )
29+ return pending
2130
22- try :
23- import keyboard
24- print (keyboard .__name__ )
25- except ImportError :
26- missingPkgs += 1
31+ def setup ():
32+ pending = get_pending_packages ()
2733
28- try :
29- import PyQt5
30- print (PyQt5 .__name__ )
31- except ImportError :
32- missingPkgs += 1
34+ if not pending :
35+ return print ('All packages are installed' )
3336
34- try :
35- import threaded
36- print (threaded .__name__ )
37- except ImportError :
38- missingPkgs += 1
37+ print (f'{ len (pending )} missing packages.\n \t Would you like to install them? (y/n)' )
3938
40- try :
41- import requests
42- print (requests .__name__ )
43- except ImportError :
44- missingPkgs += 1
39+ if input ().lower () == 'y' :
40+ for package in pending :
41+ print (f'Installing { package } ...' )
42+ install (package )
43+ print ('Installation complete' )
44+ else :
45+ print ('Installation cancelled' )
4546
47+ def main ():
4648 try :
47- import mouse
48- print (mouse .__name__ )
49- except ImportError :
50- missingPkgs += 1
51-
52- # Ask to install missing packages!
53- if missingPkgs == 0 :
54- os .system ("cls" )
55- print ("You already installed the required packages!" )
56- quit (0 )
57- else :
58- os .system ("cls" )
59- print (f"You are missing [{ missingPkgs } ] packages! \n \t Would you like to install them? \n \t (Y/N)" )
60- installSTR = str (input ("Install? > " ))
61- if installSTR .lower () == "y" :
62- os .system ("cls" )
63- try :
64- import pymem
65- except ImportError :
66- subprocess .check_call ([sys .executable , '-m' , 'pip' , 'install' , 'pymem' ])
67- try :
68- import keyboard
69- except ImportError :
70- subprocess .check_call ([sys .executable , '-m' , 'pip' , 'install' , 'keyboard' ])
71- try :
72- import PyQt5
73- except ImportError :
74- subprocess .check_call ([sys .executable , '-m' , 'pip' , 'install' , 'PyQt5' ])
75- try :
76- import threaded
77- except ImportError :
78- subprocess .check_call ([sys .executable , '-m' , 'pip' , 'install' , 'threaded' ])
79- try :
80- import requests
81- except ImportError :
82- subprocess .check_call ([sys .executable , '-m' , 'pip' , 'install' , 'requests' ])
83- try :
84- import mouse
85- except ImportError :
86- subprocess .check_call ([sys .executable , '-m' , 'pip' , 'install' , 'mouse' ])
87- os .system ("cls" )
88- print ("Finished installing packages!" )
89- quit (0 )
90- elif installSTR .lower () == "n" :
91- os .system ("cls" )
92- print ("Process aborted!" )
93- quit (0 )
94- else :
95- os .system ("cls" )
96- print ("Process aborted! \n \t (Y/N) Y = Yes | N = No" )
97- quit (0 )
49+ clear ()
50+ setup ()
9851
52+ except KeyboardInterrupt :
53+ print ('Installation cancelled by user' )
9954
10055if __name__ == '__main__' :
101- setup ()
56+ main ()
10257else :
103- print ("Installer Is not allowed to be ran, by other programs!" )
104- quit (0 )
58+ print ("Installer is not allowed to be ran, by other programs!" )
0 commit comments