Last active
May 31, 2021 20:38
-
-
Save Rainyan/0043a3342ee95ec82826683230cba557 to your computer and use it in GitHub Desktop.
Short shell & batch utility scripts for upgrading all pip packages at once.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ECHO off | |
SETLOCAL EnableDelayedExpansion | |
SET PIP_LIST_OUTDATED=pip list --outdated --format=freeze | |
REM Whether or not to run a virus scan if there were updates. | |
REM You can configure the virus scanner options in the :VirusScan label. | |
SET SCAN_FOR_VIRUSES_POST_UPDATE=1 | |
ECHO !date! - !time! :: Updating outdated pip packages... | |
SET NUM_UPGRADED=0 | |
FOR /F "tokens=1,2 delims==" %%a in ('%PIP_LIST_OUTDATED%') DO ( | |
ECHO !date! - !time! :: Updating %%a | |
pip install --user --upgrade %%a | |
SET /A NUM_UPGRADED=NUM_UPGRADED+1 | |
) | |
ECHO !date! - !time! :: Upgraded %NUM_UPGRADED% package(s) total. | |
IF %NUM_UPGRADED% GTR 0 GOTO VirusScan | |
GOTO End | |
:VirusScan | |
IF %SCAN_FOR_VIRUSES_POST_UPDATE% EQU 0 GOTO End | |
SET PYTHON_FILES="%localappdata%\Programs\Python" | |
SET ANTIVIRUS_BIN="C:\Program Files\Windows Defender\MpCmdRun.exe" | |
SET ANTIVIRUS_SCAN_OPTIONS=-Scan -ScanType 3 -File %PYTHON_FILES% | |
SET ANTIVIRUS_UPDATE_OPTIONS=-SignatureUpdate | |
ECHO !date! - !time! :: Post-upgrade: Scanning Python files (%PYTHON_FILES%) for viruses... | |
%ANTIVIRUS_BIN% %ANTIVIRUS_UPDATE_OPTIONS% | |
%ANTIVIRUS_BIN% %ANTIVIRUS_SCAN_OPTIONS% | |
:End | |
ECHO !date! - !time! :: Done. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Based on: https://stackoverflow.com/a/3452888 | |
pip list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment