Skip to content

Instantly share code, notes, and snippets.

@18520339
Last active March 20, 2022 10:33
Show Gist options
  • Save 18520339/c3bb7ab557d89141c5ce873317ddffab to your computer and use it in GitHub Desktop.
Save 18520339/c3bb7ab557d89141c5ce873317ddffab to your computer and use it in GitHub Desktop.
Install Python amd64 via Windows Powershell
# Ask for administrator privilege
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Start-Process PowerShell -Verb RunAs "-NoProfile -ExecutionPolicy Bypass -Command `"cd '$pwd'; & '$PSCommandPath';`"";
exit;
}
# Check if Python exists before installation
if(&{python -V} 2>&1 -is [System.Management.Automation.ErrorRecord]) {
$TEMP_DIR = [System.IO.Path]::GetTempPath()
$PYTHON_VERSION = "3.8.10" # Specify Python version from https://www.python.org/downloads/windows
$SAVED_NAME = "python-$PYTHON_VERSION-amd64.exe"
$DOWNLOAD_URL = "https://www.python.org/ftp/python/$PYTHON_VERSION/$SAVED_NAME"
bitsadmin.exe /transfer "Download Python $PYTHON_VERSION" $DOWNLOAD_URL $TEMP_DIR$SAVED_NAME
cd $TEMP_DIR
Invoke-Expression ".\$SAVED_NAME /quiet InstallAllUsers=0 PrependPath=1 Include_test=0"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment