WHY ARE YOU READING THIS? Python 2 has been at the end of its life since January 1, 2020. It is no longer having security vulnerabilities patched. You should go read Installing Python 3 in Git Bash on Windows 10.
Python is one of the easiest to learn programming languages. It supports developing on Linux, Mac, and Windows. To install Python on Windows, you must have your OS in developer mode.
To install Python 2.7 on Windows:
- Browse to https://www.python.org/downloads/windows/
- Click the link for the latest Python 2.7. E.g.: Latest Python 2 Release – Python 2.7.14
- Click the Windows x86-64 MSI installer link
- Once the .msi file is downloaded and scanned, double click on it
- Follow the installer instructions
- Make sure to select the feature Add python.exe to Path
Once installed, verify it works from power shell by typing: python -V
If you want to run a python script, you must give it the .py extension. Windows has a thing about extensions, and doesn’t know about shebangs (#!). Running a script from PowerShell will cause a command window to pop up while the script runs, then immediately close, making it impossible to read the output of the script if any.
This can be fixed by adding a line to your PowerShell profile:
- Run: Test-Path $profile
- If the command prints False, run: New-item –type file –force $profile
- The file Microsoft.PowerShell_profile.ps1 will be created automatically in your Documents/PowerShell directory.
- Edit the profile and insert the line:
$env:PATHEXT += ";.py"
- Restart PowerShell
- If it gives you an error saying “…running scripts is disabled…”:
- run: Set-ExecutionPolicy -Scope CurrentUser RemoteSigned
- Restart again
You should now be able to run a script. If the script is in the current directory, make sure to prefix the name with “./“