Running Python in PowerShell?


I am attempting to learn the very basics of Python using the guide “Learn Python the hard way” by Zed A. Shaw. The problem that I am having is that I can run Python scripts, but only when using . in front of the name. This opens up CMD for a split second and then closes.

If I attempt to run the file it returns that the file is not an operable program file, script, etc..

I’ve found multiple questions on Stack Overflow that relate to this question, but none of the solutions have worked for me.

Two things I’ve tried:

[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:Python27", "User")


$env:PATH =$env:PATH+";."

(How do you remove the PowerShell requirement that scripts and executables be preceded by "."?)

When I check the environment variable PATH it has the correct path within it, so what other things could be causing this?

Asked By: Scherf



Since, you are able to run Python in PowerShell. You can just do python <scriptName>.py to run the script. So, for a script named containing

name = raw_input("Enter your name: ")
print "Hello, " + name

The PowerShell session would be

PS C:Python27> python
Enter your name: Monty Python
Hello, Monty Python
PS C:Python27>
Answered By: Sukrit Kalra

As far as I have understood your question, you have listed two issues.


You are not able to execute the Python scripts by double clicking the Python file in Windows.


The script runs too fast to be seen by the human eye.


Add input() in the bottom of your script and then try executing it with double click. Now the cmd will be open until you close it.


print("Hello World")


./ issue


Use Tab to autocomplete the filenames rather than manually typing the filename with ./ autocomplete automatically fills all this for you.


CD into the directory in which .py files are present and then assume the filename is then type python te and then press Tab, it will be automatically converted to python ./

Answered By: ajknzhol

Go to Control PanelSystem and SecuritySystem, and then click Advanced system settings on the left hand side menu.

On the Advanced tab, click Environment Variables.

Under ‘User variables’ append the PATH variable with path to your Python install directory:

Answered By: David Douglas

The command [Environment]::SetEnvironmentVariable(“Path”, “$env:Path;C:Python27”, “User”) is not a Python command. Instead, this is an operating system command to the set the PATH variable.

You are getting this error as you are inside the Python interpreter which was triggered by the command python you have entered in the terminal (Windows PowerShell).

Please note the >>> at the left side of the line. It states that you are on inside Python interpreter.

Please enter quit() to exit the Python interpreter and then type the command. It should work!

Answered By: user2145645

The default execution policy, “Restricted”, prevents all scripts from running, including scripts that you write on the local computer.

The execution policy is saved in the registry, so you need to change it only once on each computer.

To change the execution policy, use the following procedure:

  1. Start Windows PowerShell with the “Run as administrator” option.

  2. At the command prompt, type:

    Set-ExecutionPolicy AllSigned


    Set-ExecutionPolicy RemoteSigned

The change is effective immediately.

To run a script, type the full name and the full path to the script file.

For example, to run the Get-ServiceLog.ps1 script in the C:Scripts directory, type:


And to the Python file, you have two points. Try to add your Python folder to your PATH and the extension .py.

To PATHEXT from go properties of computer. Then click on advanced system protection. Then environment variable. Here you will find the two points.

Answered By: Mustafa jahjoum

Using CMD you can run your python scripts as long as the installed python is added to the path with the following line:

C:  Python27;

The (27) is example referring to version 2.7, add as per your version.

Path to system path:

Control Panel => System and Security => System => Advanced Settings => Advanced => Environment Variables.

Under “User Variables,” append the PATH variable to the path of the Python installation directory (As above).

Once this is done, you can open a CMD where your scripts are saved, or manually navigate through the CMD.

To run the script enter:

C:  User  X  MyScripts> python
Answered By: Lucas Coelho

Go to Python Website/dowloads/windows.
Download Windows x86-64 embeddable zip file.
2. Open Windows Explorer

open zipped folder python-3.7.0
In the windows toolbar with the Red flair saying “Compressed Folder Tool”
Press “Extract” button on the tool bar with “File” “Home “Share” “View”
Select Extract all
Extraction process is not covered yet
Once extracted save onto SDD or fastest memory device. Not usb.
HDD is fine.
Users/butte/ProgramFiles blah blah ooooor
Or Hook up to your cloud
3. Click your User Icon in the Windows tool bar.

Search environment variable
Proceed with progressing with “Environment Variables” button press
Under the “user variables” table select “New..” After the Canvas of Information
Add Python in Variable Name
Select the “D:Pythonpython-3.7.0-embed-amd64python.exe;”
click ok
Under the “System Variables” label and in the Canvas the first row has a value marked “Path”
Select “Edit” when “Path” is highlighted.
Select “New”
Enter D:Pythonpython-3.7.0-embed-amd
click ok
Ok Save and double check
Open Power Shell
python –help

python –version

Source to tutorial

Answered By: Whitney Kretz
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.