If you want to use PowerShell to execute Python scripts, you need to have Python installed or you will receive the error below:

Powershell:- running python script fails with error.

Head over to the Microsoft store and download Python. I opted for Python 3.7 but there are newer versions out:

Powershell:- running python script fails with error.

After the install was done, I opened up notepad and created a simple file called PowerShellCheck and saved it with a .py extension in the directory where I have Python 3.7 installed. Here is the line of code:

  • print(“Running a Python Script from PowerShell”)

In the same elevated PowerShell window, I executed the script using this command line:

  • python PowerShellCheck.py

You should see an output as per the below:

Powershell:- running python script fails with error.

As you can see, it executed perfectly and printed the line I had in the script.

Hope it helps.

    wpChatIcon

    Discover more from Everything-PowerShell

    Subscribe now to keep reading and get access to the full archive.

    Continue reading