Skip to content

Instantly share code, notes, and snippets.

@EdwinChua
Last active June 30, 2017 02:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EdwinChua/4dffa11b450c408b0e81293515115cbd to your computer and use it in GitHub Desktop.
Save EdwinChua/4dffa11b450c408b0e81293515115cbd to your computer and use it in GitHub Desktop.
Setting up Python (on Windows)

Setting up Python (on Windows)

Download and run Microsoft Web Platform Installer 5.0 (WPI)

Link: https://www.microsoft.com/web/downloads/platform.aspx

Search for Python in WPI

  • Choose either Python 3.X.X or Python 2.7.X, depending on what you require
  • You can install both side by side

Quickstart with IDLE

  • Once installed, search for IDLE in your start menu and run it
  • A IDLE shell window should pop up with:
Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 17:54:52) [MSC v.1900 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> 
  • Execute single line commands for fun!
    • >>> print("hello world")
    • Output: hello world

Create your first python script

  • In the IDLE shell window, go to: File > new file (or new window, depending on python version)
  • In the new window that appears, type print("hello world"), and click Run > Run module (or press F5)
  • You will be prompted to save the file first
  • Once saved, the script will run, and the output will be printed on the IDLE window

That's all! IDLE is sufficient for everyday use. If you are interested, check out Visual Studio 2017. (Community version is free. Note that you can let VS2017 install a copy of Python)

For good text editors, check out Sublime Text, Brackets or Atom.

Advanced stuff

Check if the PATH has been configured for you (Optional, but recommended)

  • Open a command prompt window
  • Type 'python' and press enter
  • If you get "'python' is not recognized as an internal or external command, operable program or batch file.", read on
  • Locate your Python installation
    • It should either be in C:\ (eg. C:\Python27, C:\Users\[UserName]\AppData\Local\Programs\Python\Python36-32,C:\Program Files\Python36)
    • If you can't find it, do a system-wide search for "python"
    • The folder you want contains the python.exe file (or python3.exe, maybe)
  • Once you have your Python installation folder location, follow the guide here to add it to your path variable

What is a PATH variable?

It is a shortcut to the executable file (.exe) in your folder. Benefit = Less typing.

Example

  • Lets say your python compiler is found at C:\Python\python.exe and your python script is at C:\Documents\myscript.py
    • These are known as fully qualified paths.
  • To compile your program, you would need to type the following in your terminal:
    • If in Python folder: python C:\Documents\myscript.py
    • If in myscript folder: C:\Python\python.exe myscript.py
    • Anywhere else: C:\Python\python.exe C:\Documents\myscript.py
  • As you can see, it is in the format: executable script.py
  • Adding a folder to your PATH allows the executable to be accessed regardless of where you are in the command terminal. i.e.:
    • If in myscript folder python myscript.py notice that this is very very short!
    • Anywhere else: python C:\Documents\myscript.py

Testing your setup

  • Open a command window
  • Run your python compiler
    • Simply, python, or if the path is not configured, use the fully qualified path
  • You should see the following output:
Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 17:54:52) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
  • Notice your Python version is printed there.
  • Execute single line commands for fun!
    • >>> print("hello world")
    • Output: hello world
  • To exit your compiler, type exit() or press ctrl+z and enter

Congratulations! You have completed your Python setup!

Other things to do

Add pip to PATH variables

  • Add [PythonInstallationPath]/Scripts to your PATH variable
  • Also check if the folder contains pip.exe or other versions of it
  • This allows you to use pip install [package name] to get other python packages
  • If you don't think its necessary to add this to your PATH variables, simply navigate to this folder and run the pip install [package name] when you need another package
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment