An open API service indexing awesome lists of open source software.

https://github.com/samix3108/purge

Um simples código que limpa o cache e remove pacotes baixados no ambiente Python.
https://github.com/samix3108/purge

clear pip purge python

Last synced: 2 months ago
JSON representation

Um simples código que limpa o cache e remove pacotes baixados no ambiente Python.

Awesome Lists containing this project

README

        

This code is a Python utility for uninstalling all installed Python packages in the current environment and clearing the pip cache. It is especially useful for resetting development environments or freeing up disk space.

---

### Code Description

#### Objective
The script automates two common processes for developers or system administrators who want to reset or clean the Python environment:

1. **Uninstall all installed Python packages:**
- Uses the `pip freeze` command to list installed packages and then uninstalls each one.
- The uninstallation is done automatically without asking for confirmations, thanks to the `-y` parameter.

2. **Clear the pip cache:**
- Removes the temporary files stored by pip, saving disk space and ensuring a cleaner environment.

---

#### Key Components

1. **Function `uninstall_all_packages`:**
- Lists all installed packages using `pip freeze`.
- Uninstalls each identified package.
- Handles errors that may occur during listing or uninstallation.

2. **Function `clear_pip_cache`:**
- Executes the `pip cache purge` command to clear cache files.
- Displays messages indicating the success or failure of the operation.

3. **Main Block (`if __name__ == "__main__"`):**
- Calls the functions in sequence: first uninstalls the packages, then clears the cache.
- Displays status messages to inform progress.

---

#### Practical Application
This script is useful for:
- Resetting Python environments on development or production machines.
- Cleaning the environment before setting up new packages or dependencies.
- Saving disk space by removing unnecessary packages and cache files.

#### Warning
**Attention:** This code removes all installed packages in the Python environment, which can impact configured or in-development systems. Use it with caution and preferably in isolated environments (such as virtualenvs or containers).