Installing Python 2.7 on Windows

python-logoPython 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:

  1. Browse to https://www.python.org/downloads/windows/
  2. Click the link for the latest Python 2.7. E.g.: Latest Python 2 Release – Python 2.7.14
  3. Click the Windows x86-64 MSI installer link
  4. Once the .msi file is downloaded and scanned, double click on it
  5. 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:

  1. Run: Test-Path $profile
  2. 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.
  3. Edit the profile and insert the line:
    $env:PATHEXT += ";.py"
  4. Restart PowerShell
  5. If it gives you an error saying “…running scripts is disabled…”:
    1. run: Set-ExecutionPolicy -Scope CurrentUser RemoteSigned
    2. 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 “./

Advertisements

About jimbelton

I'm a software developer, and a writer of both fiction and non-fiction, and I blog about movies, books, and philosophy. My interest in religious philosophy and the search for the truth inspires much of my writing.
This entry was posted in programming and tagged , , , , . Bookmark the permalink.

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s