Powershell

Run Python in PowerShell

PowerShell is a CLI (Command Line Interface) tool, and it has the capability to run almost all CLI tools inside it. More specifically, python is one of the CLI tools and can be executed in PowerShell. This programming language provides high-level functionality to develop websites and applications.

This post will elaborate on a procedure to run Python in PowerShell.

How to Run Python in PowerShell?

In order to run Python in PowerShell, Python must already be installed on Windows. If it is not already installed, read our other dedicated post.

After that, Python can simply be executed by invoking the “Python” command in PowerShell. Moreover, Python script can also be executed inside the PowerShell console.

The demonstrations of running Python in PowerShell are provided in the further post.

Example 1: Run Python in PowerShell

This example will demonstrate the method to run Python in PowerShell by invoking the “Python” command:

> Python

The output confirms that the Python has been executed successfully in PowerShell.

Example 2: Execute Python Code in PowerShell

As we have enabled Python in PowerShell, now let’s print the “Hello World” message in Python:

> Print("Hello World")

The above-given “Print()” command is used in Python to print the text to output:

It can be observed that the specified message has been printed out on the console.

Example 3: Run Python Script in PowerShell

You can also execute a Python script in PowerShell as follows:

> Python C:\New\Test.py

Note: In case you don’t know how to create a Python script, then read this post.

Here, the Python command will execute the specified file:

That was all about running Python in PowerShell.

Conclusion

To run Python in PowerShell, simply run the “Python” command to enable the Python development environment. After that, you can execute any of the Python commands inside PowerShell. Moreover, you can also run Python scripts. For that reason, first, write the Python command and then add the Python script file path. This tutorial has presented a detailed procedure to run Python in PowerShell.

About the author

Muhammad Farhan

I am a Computer Science graduate and now a technical writer who loves to provide the easiest solutions to the most difficult problems related to Windows, Linux, and Web designing. My love for Computer Science emerges every day because of its ease in our everyday life.