Run Python Script From Command Prompt

Environment Setup

Why we need to set Environment ?

  • python is the name of interpreter for Python programming language.
  • python.exe interpreter is present inside Python installation directory usually in Program Files.
  • Hence we need to tell OS about python interpreter.
  • Set Python installation directory to the PATH variable.

Set up PATH

  • Go to the directory where python.exe file is present.

  • Usually inside “C:\Program Files\Python 3.5”.
  • Copy this location from address bar.
  • Now go to the System properties.
  • Click on Advanced System Settings.

  • Click on Environment Variables.
  • Under user variable click on New…
  • Give variable name as PATH (or path)
  • Paste the copied location inside Variable Value.

  • Click on OK ,OK, OK.

Note –

  • If you have previously created PATH variable then click on Edit.
  • Add a Semicolon to the existing value.
  • Then paste the copied location.
  • Then OK, OK, OK.

Write Python code to notepad.

  • Create a folder on Desktop with any name.
  • “Python Programs” in my case.
  • Open the folder and  in the address bar type “cmd” and hit Enter.
  • Type “notepad”  in the Command prompt.

  • In the notepad write your Python code –  print(“Hello World”).

  • Save this file.
  • Now go to the command prompt.

Run the python script from command prompt.

  • Type python (python

  • Python programs have .py extension.
  • You will see “Hello World” in the command prompt.