Run this script directly
curl -Lks bit.ly/pipclear | pythonRun this script directly
curl -Lks bit.ly/pipclear | python| #! /usr/bin/env python | |
| import os | |
| from typing import List | |
| def run(*commands: str) -> None: | |
| for cmd in commands: | |
| try: | |
| status = os.system(cmd) | |
| if status != 0: | |
| raise Exception(f"{cmd} returned non zero exit code") | |
| except Exception as err: | |
| print(err) | |
| def ensure() -> None: | |
| os.chdir(os.path.expanduser("~")) | |
| run("pip --version", "python --version", "pwd") | |
| def python_packages() -> List[str]: | |
| run("pip freeze > python_packages") | |
| with open("python_packages") as file: | |
| packages = [package.strip() for package in file.readlines()] | |
| return packages | |
| def uninstall(packages: List[str]): | |
| for package in packages: | |
| run(f"pip uninstall {package} -y") | |
| run("pip cache purge") | |
| run("rm python_packages") | |
| def main(): | |
| ensure() | |
| packages = python_packages() | |
| uninstall(packages) | |
| if __name__ == "__main__": | |
| print("MIT LICENSE\nCopyright (c) 2021 Aahnik Daw") | |
| main() | |
| # AAHNIK 2021 |