Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add pip auto-updater script with support for outdated package detection and upgrade. #1023

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ayush-a-srivastava wants to merge 1 commit into python-geeks:main
base: main
Choose a base branch
Loading
from ayush-a-srivastava:install_outdated_packages
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions pip_auto_updater/README.md
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 🛠️ Pip Auto-Updater

This script automates the process of updating all outdated Python packages installed via `pip`. It’s designed for developers and QA engineers who want to maintain clean, up-to-date environments with minimal manual effort.

## Features

- Identifies all outdated packages using `pip list --outdated` excluding built-ins.
- Iteratively upgrades each package via `pip install --upgrade`, ensuring minimal disruption.
---

## Usage

### Run the script directly:
```bash
python pip_auto_updater/update_packages.py
```

## Compatibility
- Python 3.8+
- Pip 21+

## Notes
- Some packages may fail to update due to system-level constraints or dependency conflicts.
- It’s recommended to run this inside a virtual environment to avoid breaking global installs.

## Author
Ayush Srivastava
41 changes: 41 additions & 0 deletions pip_auto_updater/update_packages.py
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import subprocess
import sys

def update_outdated_packages():
"""
Updates all outdated third-party Python packages using pip.
Built-in and system packages are excluded.
"""
try:
# Get list of outdated packages
result = subprocess.run(
[sys.executable, "-m", "pip", "list", "--outdated", "--format=json"],
capture_output=True, text=True, check=True
)
outdated = eval(result.stdout) # JSON parsing without import for simplicity

if not outdated:
print("All packages are up to date.")
return

print(f"Found {len(outdated)} outdated packages. Updating...\n")

for pkg in outdated:
name = pkg['name']
current_version = pkg['version']
latest_version = pkg['latest_version']
print(f"Updating {name} ({current_version} → {latest_version})...")

try:
subprocess.run(
[sys.executable, "-m", "pip", "install", "--upgrade", name],
check=True
)
print(f"✅ {name} updated successfully.\n")
except subprocess.CalledProcessError:
print(f"Failed to update {name}. Skipping...\n")

except Exception as e:
print(f"Error occurred: {e}")

update_outdated_packages()
Loading

AltStyle によって変換されたページ (->オリジナル) /