Skip to content

Python Script to Update all Packages with Pip (Windows, Linux, Mac, ChromeOS, etc)

RileyXX edited this page Jun 6, 2023 · 3 revisions
  1. Create a new .txt file and rename it to AutoUpdatePythonPackages.py
  2. Open AutoUpdatePythonPackages.py file in a text editor, copy the following code and save it to the .py file.
import subprocess

# Add or remove which python packages/projects you would like to ignore from auto-updates
# e.g. ['Project 1', 'Project 2', 'Project 3'] or no packages with []
ignored_packages = ['chromedriver-py']

subprocess.call(['pip', 'install', '--upgrade', 'pip'])

# Get a list of outdated packages
outdated_packages = subprocess.check_output(['pip', 'list', '--outdated']).decode().split('\n')

# Update each outdated package (excluding chromedriver-py)
for package in outdated_packages:
    if package:
        package_name = package.split(' ')[0]
        if package_name not in ignored_packages:
            subprocess.call(['pip', 'install', '-U', package_name])

if not outdated_packages:
    print("All packages are up to date.")
  1. Run the file.
  2. (Optional) Edit the ignored_packages value to exclude packages and projects from auto-updating.