|
1 |
| -import importlib |
2 | 1 | import os
|
3 | 2 | import subprocess
|
| 3 | +import importlib |
4 | 4 | import pkgutil
|
5 | 5 |
|
6 | 6 | if pkgutil.find_loader("colorama") is None:
|
|
12 | 12 | colorama.init(autoreset=True)
|
13 | 13 |
|
14 | 14 | 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") |
18 | 20 | print('''
|
19 | 21 | (1) Install package
|
20 |
| - (2) Batch install |
| 22 | + (2) Batch install from requirements file |
21 | 23 | (3) Update package
|
22 | 24 | (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''') |
25 | 29 |
|
26 |
| -#------------------------------------------------------------------------------------------------ |
27 |
| -package_list = ["pyperclip", "numpy", "colorama", "pytz"] #Enter packages you need to install |
28 |
| -#------------------------------------------------------------------------------------------------ |
29 | 30 |
|
30 | 31 | while True:
|
31 | 32 | option = input(Fore.CYAN + " Enter option: " + Style.RESET_ALL)
|
|
34 | 35 | install_pkg = input(Fore.CYAN + " Enter package name: " + Style.RESET_ALL)
|
35 | 36 |
|
36 | 37 | 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: |
42 | 38 | subprocess.check_call(["pip", "install", install_pkg])
|
43 | 39 | print(" " + Fore.BLACK + Back.GREEN + f" Installed {install_pkg} ")
|
44 | 40 | print()
|
45 | 41 | 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...") |
46 | 46 | break
|
47 | 47 |
|
48 | 48 | elif option == "2":
|
49 | 49 | 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...") |
53 | 52 |
|
54 |
| - for pkg in package_list: |
| 53 | + with open("requirements.txt") as f: |
| 54 | + reqs = f.read().splitlines() |
| 55 | + for pkg in reqs: |
55 | 56 | try:
|
56 | 57 | subprocess.check_call(["pip", "install", pkg])
|
57 | 58 | print(" " + Fore.BLACK + Back.GREEN + f" Installed {pkg} ")
|
58 | 59 | print()
|
59 | 60 | except subprocess.CalledProcessError:
|
60 |
| - print(" " + Fore.BLACK + Back.RED + " PACKAGE NOT FOUND ") |
| 61 | + print(" " + Fore.BLACK + Back.RED + " AN ERROR OCCURED ") |
61 | 62 | print()
|
62 | 63 | input(" Press Enter to exit...")
|
63 | 64 | break
|
|
94 | 95 |
|
95 | 96 | elif option == "5":
|
96 | 97 | 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) |
98 | 99 | print(Fore.RED + " Batch uninstalling packages..." + Style.RESET_ALL)
|
99 | 100 | print()
|
100 | 101 |
|
101 |
| - for pkg in package_list: |
| 102 | + with open("requirements.txt") as f: |
| 103 | + reqs = f.read().splitlines() |
| 104 | + for pkg in reqs: |
102 | 105 | 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} ") |
105 | 108 | print()
|
106 | 109 | except subprocess.CalledProcessError:
|
107 | 110 | print(" " + Fore.BLACK + Back.RED + " PACKAGE NOT FOUND ")
|
108 | 111 | print()
|
109 | 112 | input(" Press Enter to exit...")
|
| 113 | + #os._exit(0) |
110 | 114 | break
|
111 | 115 |
|
112 | 116 | elif option == "6":
|
|
123 | 127 | print()
|
124 | 128 | input(" Press Enter to exit...")
|
125 | 129 | 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 |
126 | 158 | else:
|
127 | 159 | print(" " + Fore.BLACK + Back.RED + " INVALID OPTION ")
|
128 | 160 | print()
|
| 161 | + |
| 162 | + |
| 163 | +# Copyright © 2023 Ashfaaq Rifath - PipWizard v1.5.0 |
0 commit comments