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.
- Host: GitHub
- URL: https://github.com/samix3108/purge
- Owner: samix3108
- License: mit
- Created: 2025-01-10T19:45:28.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2025-02-19T23:39:04.000Z (3 months ago)
- Last Synced: 2025-02-20T00:31:52.912Z (3 months ago)
- Topics: clear, pip, purge, python
- Language: Python
- Homepage:
- Size: 7.81 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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).