PowerShell Troubleshooting: Running Python script fails with error
If you want to use PowerShell to execute Python scripts, you need to have Python installed or you will receive the error below:
https://everything-powershell.com/wp-content/uploads/2020/12/image-6.png
Head over to the Microsoft store and download Python. I opted for Python 3.7 but there are newer versions out:
https://everything-powershell.com/wp-content/uploads/2020/12/image-7.png
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:
https://everything-powershell.com/wp-content/uploads/2020/12/image-8.png
As you can see, it executed perfectly and printed the line I had in the script.