Skip to content

Commit c2dcd42

Browse files
Update pipwizard.py
1 parent 8e5e6b8 commit c2dcd42

File tree

1 file changed

+59
-24
lines changed

1 file changed

+59
-24
lines changed

pipwizard.py

Lines changed: 59 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import importlib
21
import os
32
import subprocess
3+
import importlib
44
import pkgutil
55

66
if pkgutil.find_loader("colorama") is None:
@@ -12,20 +12,21 @@
1212
colorama.init(autoreset=True)
1313

1414
os.system("cls")
15-
print()
16-
print(" " + Fore.BLACK + Back.YELLOW + " PIPWIZARD - Package Manager ")
17-
print(Fore.LIGHTBLACK_EX + " Copyright © 2023 Ashfaaq Rifath - PipWizard v1.4.0")
15+
print('''
16+
█▀▀█ ▀█▀ █▀▀█ █ █ ▀█▀ █▀▀▀█ █▀▀█ █▀▀█ █▀▀▄
17+
█▄▄█ █ █▄▄█ █ █ █ █ ▄▄▄▀▀ █▄▄█ █▄▄▀ █ █
18+
█ ▄█▄ █ █▄▀▄█ ▄█▄ █▄▄▄█ █ █ █ █ █▄▄▀ v1.5.0''')
19+
print(Fore.YELLOW + " PYTHON PACKAGE MANAGER")
1820
print('''
1921
(1) Install package
20-
(2) Batch install
22+
(2) Batch install from requirements file
2123
(3) Update package
2224
(4) Uninstall package
23-
(5) Batch uninstall
24-
(6) Check package status''')
25+
(5) Batch uninstall from requirements file
26+
(6) Check package status
27+
(7) Display installed packages
28+
(8) Save requirements file''')
2529

26-
#------------------------------------------------------------------------------------------------
27-
package_list = ["pyperclip", "numpy", "colorama", "pytz"] #Enter packages you need to install
28-
#------------------------------------------------------------------------------------------------
2930

3031
while True:
3132
option = input(Fore.CYAN + " Enter option: " + Style.RESET_ALL)
@@ -34,30 +35,30 @@
3435
install_pkg = input(Fore.CYAN + " Enter package name: " + Style.RESET_ALL)
3536

3637
try:
37-
importlib.import_module(install_pkg)
38-
print(" " + Fore.BLACK + Back.GREEN + f" {install_pkg} already installed ")
39-
print()
40-
input(" Press Enter to exit...")
41-
except ImportError:
4238
subprocess.check_call(["pip", "install", install_pkg])
4339
print(" " + Fore.BLACK + Back.GREEN + f" Installed {install_pkg} ")
4440
print()
4541
input(" Press Enter to exit...")
42+
except subprocess.CalledProcessError:
43+
print(" " + Fore.BLACK + Back.RED + " PACKAGE NOT FOUND ")
44+
print()
45+
input(" Press Enter to exit...")
4646
break
4747

4848
elif option == "2":
4949
print()
50-
print(Fore.YELLOW + " (●) Make sure package list is modified in the source code." + Style.RESET_ALL)
51-
print(Fore.GREEN + " Batch installing packages..." + Style.RESET_ALL)
52-
print()
50+
print(Fore.YELLOW + " NOTE: Make sure requirements.txt is in this directory.")
51+
print(Fore.GREEN + " Batch installing packages...")
5352

54-
for pkg in package_list:
53+
with open("requirements.txt") as f:
54+
reqs = f.read().splitlines()
55+
for pkg in reqs:
5556
try:
5657
subprocess.check_call(["pip", "install", pkg])
5758
print(" " + Fore.BLACK + Back.GREEN + f" Installed {pkg} ")
5859
print()
5960
except subprocess.CalledProcessError:
60-
print(" " + Fore.BLACK + Back.RED + " PACKAGE NOT FOUND ")
61+
print(" " + Fore.BLACK + Back.RED + " AN ERROR OCCURED ")
6162
print()
6263
input(" Press Enter to exit...")
6364
break
@@ -94,19 +95,22 @@
9495

9596
elif option == "5":
9697
print()
97-
print(Fore.YELLOW + " (●) Make sure package list is modified in the source code." + Style.RESET_ALL)
98+
print(Fore.YELLOW + " NOTE: Input package names in the requirements file." + Style.RESET_ALL)
9899
print(Fore.RED + " Batch uninstalling packages..." + Style.RESET_ALL)
99100
print()
100101

101-
for pkg in package_list:
102+
with open("requirements.txt") as f:
103+
reqs = f.read().splitlines()
104+
for pkg in reqs:
102105
try:
103-
subprocess.check_call(["pip", "uninstall", pkg])
104-
print(" " + Fore.BLACK + Back.RED + f" Uninstalled {pkg} ")
106+
subprocess.check_call(["pip", "uninstall", "-y", pkg])
107+
print(" " + Fore.BLACK + Back.RED + f" Uinstalled {pkg} ")
105108
print()
106109
except subprocess.CalledProcessError:
107110
print(" " + Fore.BLACK + Back.RED + " PACKAGE NOT FOUND ")
108111
print()
109112
input(" Press Enter to exit...")
113+
#os._exit(0)
110114
break
111115

112116
elif option == "6":
@@ -123,6 +127,37 @@
123127
print()
124128
input(" Press Enter to exit...")
125129
break
130+
131+
elif option == "7":
132+
print()
133+
print(Fore.GREEN + " Displaying all installed packages...")
134+
135+
subprocess.check_call(["pip", "list"])
136+
print()
137+
input(" Press Enter to exit...")
138+
break
139+
140+
elif option == "8":
141+
print()
142+
print(Fore.YELLOW + " NOTE: Copy this tool to the project folder ")
143+
print(Fore.GREEN + " Saving project requirements to text file...")
144+
145+
try:
146+
save = subprocess.run(["pip", "freeze"], stdout=subprocess.PIPE)
147+
with open('requirements.txt', 'wb') as f:
148+
f.write(save.stdout)
149+
150+
print(" " + Fore.BLACK + Back.GREEN + " PROJECT REQUIREMENTS SAVED ")
151+
print()
152+
input(" Press Enter to exit...")
153+
except subprocess.CalledProcessError:
154+
print(" " + Fore.BLACK + Back.RED + " AN ERROR OCCURED ")
155+
print()
156+
input(" Press Enter to exit...")
157+
break
126158
else:
127159
print(" " + Fore.BLACK + Back.RED + " INVALID OPTION ")
128160
print()
161+
162+
163+
# Copyright © 2023 Ashfaaq Rifath - PipWizard v1.5.0

0 commit comments

Comments
 (0)