Skip to content

Commit 2bcbeaa

Browse files
Add files via upload
1 parent d046f07 commit 2bcbeaa

File tree

1 file changed

+223
-0
lines changed

1 file changed

+223
-0
lines changed

PyWizard.py

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
import os
2+
import sys
3+
import subprocess
4+
import importlib
5+
import pkgutil
6+
7+
if pkgutil.find_loader("colorama") is None:
8+
subprocess.check_call(["pip", "install", "colorama"])
9+
#installs colorama automatically
10+
else:
11+
pass
12+
import colorama
13+
from colorama import Fore, Back, Style
14+
colorama.init(autoreset=True)
15+
16+
#clears terminal
17+
os.system("cls")
18+
print('''
19+
█▀▀█ █ █ █ █ ▀█▀ █▀▀▀█ █▀▀█ █▀▀█ █▀▀▄
20+
█▄▄█ █▄▄▄█ █ █ █ █ ▄▄▄▀▀ █▄▄█ █▄▄▀ █ █
21+
█ █ █▄▀▄█ ▄█▄ █▄▄▄█ █ █ █ █ █▄▄▀ v1.5.4''')
22+
print(Fore.YELLOW + " PYTHON PACKAGE MANAGER")
23+
print()
24+
print(Fore.LIGHTBLACK_EX + " Copyright © Ashfaaq Rifath")
25+
26+
print('''
27+
(1) Install package
28+
(2) Batch install from requirements file
29+
(3) Update package
30+
(4) Uninstall package
31+
(5) Batch uninstall from requirements file
32+
(6) Check package status
33+
(7) Display installed packages
34+
(8) Save requirements file
35+
(9) Upgrade PIP version
36+
(10) Check PIP version
37+
(11) Check Python version
38+
(12) Create EXE for Python file''')
39+
40+
while True:
41+
print()
42+
option = input(Fore.CYAN + " Select option: " + Style.RESET_ALL)
43+
if option == "1":
44+
print()
45+
install_pkg = input(Fore.CYAN + " Enter package name: " + Style.RESET_ALL)
46+
47+
try:
48+
subprocess.check_call(["pip", "install", install_pkg])
49+
print(" " + Fore.BLACK + Back.GREEN + f" Installed {install_pkg} ")
50+
except subprocess.CalledProcessError:
51+
print(" " + Fore.BLACK + Back.RED + " PACKAGE NOT FOUND ")
52+
53+
elif option == "2":
54+
print()
55+
print(Fore.YELLOW + " NOTE: Make sure requirements.txt is in the root directory.")
56+
if os.path.isfile("requirements.txt"):
57+
print(Fore.GREEN + " Batch installing packages...")
58+
59+
with open("requirements.txt") as f:
60+
reqs = f.read().splitlines()
61+
for pkg in reqs:
62+
try:
63+
subprocess.check_call(["pip", "install", pkg])
64+
print(" " + Fore.BLACK + Back.GREEN + f" Installed {pkg} ")
65+
print()
66+
except subprocess.CalledProcessError:
67+
print(" " + Fore.BLACK + Back.RED + " ERROR OCCURRED ")
68+
else:
69+
print(" " + Fore.BLACK + Back.RED + " REQUIREMENTS FILE DOES NOT EXIST ")
70+
71+
elif option == "3":
72+
print()
73+
update_pkg = input(Fore.GREEN + " Enter package name: " + Style.RESET_ALL)
74+
75+
try:
76+
subprocess.check_call(["pip", "install", "--upgrade", update_pkg])
77+
print(" " + Fore.BLACK + Back.GREEN + f" Updated {update_pkg} ")
78+
except subprocess.CalledProcessError:
79+
print(" " + Fore.BLACK + Back.RED + " PACKAGE NOT FOUND ")
80+
81+
elif option == "4":
82+
print()
83+
uninstall_pkg = input(Fore.LIGHTRED_EX + " Enter package name: " + Style.RESET_ALL)
84+
85+
try:
86+
subprocess.check_call(["pip", "uninstall", uninstall_pkg])
87+
print(" " + Fore.BLACK + Back.RED + f" Uninstalled {uninstall_pkg} ")
88+
except subprocess.CalledProcessError:
89+
print(" " + Fore.BLACK + Back.RED + " PACKAGE NOT FOUND ")
90+
91+
elif option == "5":
92+
confirm = input(Fore.LIGHTRED_EX + " Do you want to proceed? (y/n): ")
93+
if confirm == "y".lower():
94+
print()
95+
print(Fore.YELLOW + " NOTE: Input package names in the requirements file." + Style.RESET_ALL)
96+
if os.path.isfile("requirements.txt"):
97+
print(Fore.RED + " Batch uninstalling packages..." + Style.RESET_ALL)
98+
print()
99+
100+
with open("requirements.txt") as f:
101+
reqs = f.read().splitlines()
102+
for pkg in reqs:
103+
try:
104+
subprocess.check_call(["pip", "uninstall", "-y", pkg])
105+
print(" " + Fore.BLACK + Back.RED + f" Uninstalled {pkg} ")
106+
except subprocess.CalledProcessError:
107+
print(" " + Fore.BLACK + Back.RED + " PACKAGE NOT FOUND ")
108+
else:
109+
print(" " + Fore.BLACK + Back.RED + " REQUIREMENTS FILE DOES NOT EXIST ")
110+
else:
111+
print(" " + Fore.BLACK + Back.RED + " UNINSTALL CANCELLED ")
112+
113+
elif option == "6":
114+
print()
115+
verify_pkg = input(Fore.CYAN + " Enter package name: " + Style.RESET_ALL)
116+
117+
try:
118+
subprocess.check_call(["pip", "show", verify_pkg])
119+
print(" " + Fore.BLACK + Back.GREEN + f" {verify_pkg} package exists ")
120+
except subprocess.CalledProcessError:
121+
print(" " + Fore.BLACK + Back.RED + " PACKAGE NOT FOUND ")
122+
123+
elif option == "7":
124+
print()
125+
print(Fore.GREEN + " Displaying all installed packages...")
126+
subprocess.check_call(["pip", "list"])
127+
128+
elif option == "8":
129+
print()
130+
print(Fore.YELLOW + " NOTE: Run this tool from the desired project folder.")
131+
print(Fore.GREEN + " Saving project requirements to text file...")
132+
133+
try:
134+
save = subprocess.run(["pip", "freeze"], stdout=subprocess.PIPE)
135+
with open('requirements.txt', 'wb') as f:
136+
f.write(save.stdout)
137+
print(" " + Fore.BLACK + Back.GREEN + " PROJECT REQUIREMENTS SAVED ")
138+
except subprocess.CalledProcessError:
139+
print(" " + Fore.BLACK + Back.RED + " ERROR OCCURRED ")
140+
141+
elif option == "9":
142+
print()
143+
print(Fore.GREEN + " Upgrading to new PIP version...")
144+
145+
try:
146+
subprocess.run(["python", "-m", "pip", "install", "--upgrade", "pip"])
147+
print(" " + Fore.BLACK + Back.GREEN + " PIP version upgrade successful ")
148+
except subprocess.CalledProcessError:
149+
print(" " + Fore.BLACK + Back.RED + " ERROR OCCURRED ")
150+
151+
elif option == "10":
152+
print()
153+
print(Fore.GREEN + " Displaying PIP version")
154+
subprocess.run(["pip", "--version"])
155+
156+
elif option == "11":
157+
print()
158+
print(Fore.GREEN + " Displaying Python version")
159+
subprocess.run(["python", "--version"])
160+
161+
elif option == "12":
162+
if pkgutil.find_loader("pyinstaller") is None:
163+
subprocess.check_call(["pip", "install", "pyinstaller"])
164+
#installs pyinstaller automatically
165+
else:
166+
pass
167+
168+
print()
169+
file_name = input(Fore.CYAN + " Enter Python file name (.py): " + Style.RESET_ALL)
170+
171+
if os.path.isfile(file_name):
172+
icon_option = input(Fore.YELLOW + " Do you want an icon for this file? (y/n): " + Style.RESET_ALL)
173+
174+
if icon_option == "y".lower():
175+
icon_name = input(Fore.CYAN + " Enter ICO file name (.ico): " + Style.RESET_ALL)
176+
177+
if os.path.isfile(icon_name):
178+
print()
179+
print(Fore.YELLOW + " NOTE: Run this tool from the desired project folder.")
180+
print(Fore.GREEN + f" Creating EXE file for {file_name}...")
181+
182+
try:
183+
subprocess.run(["pyinstaller", "--onefile", f"--icon={icon_name}", file_name])
184+
print(" " + Fore.BLACK + Back.GREEN + f" Created EXE file for {file_name} ")
185+
except subprocess.CalledProcessError:
186+
print(" " + Fore.BLACK + Back.RED + " ERROR OCCURRED ")
187+
else:
188+
print(" " + Fore.BLACK + Back.RED + " FILE DOES NOT EXIST ")
189+
190+
if icon_option == "n".lower():
191+
print()
192+
print(Fore.YELLOW + " NOTE: Run this tool from the desired project folder.")
193+
print(Fore.GREEN + f" Creating EXE file for {file_name}...")
194+
195+
try:
196+
subprocess.run(["pyinstaller", "--onefile", file_name])
197+
print(" " + Fore.BLACK + Back.GREEN + f" Created EXE file for {file_name} ")
198+
except subprocess.CalledProcessError:
199+
print(" " + Fore.BLACK + Back.RED + " ERROR OCCURRED ")
200+
else:
201+
print(" " + Fore.BLACK + Back.RED + " FILE DOES NOT EXIST ")
202+
203+
elif option == "help":
204+
print('''
205+
(1) Install package
206+
(2) Batch install from requirements file
207+
(3) Update package
208+
(4) Uninstall package
209+
(5) Batch uninstall from requirements file
210+
(6) Check package status
211+
(7) Display installed packages
212+
(8) Save requirements file
213+
(9) Upgrade PIP version
214+
(10) Check PIP version
215+
(11) Check Python version
216+
(12) Create EXE for Python file''')
217+
218+
else:
219+
print(" " + Fore.BLACK + Back.RED + " INVALID OPTION ")
220+
221+
222+
223+
# Copyright © 2023 Ashfaaq Rifath - PyWizard v1.5.4

0 commit comments

Comments
 (0)