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:
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:
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:
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.