web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Having trouble using R...
Power Automate
Answered

Having trouble using Run Powershell Action to run Python 3 script

(0) ShareShare
ReportReport
Posted on by 431

I have a Python 3 script named main.py  It runs when executed in Pycharm. I want to run this script from PAD but can't figure out how to call it. I tried to use AI to suggest a way forward. One iteration was to create a ps1 file and call that. That file was as shown below. Can someone please point me in the right direction. TIA

# Specify the path to your Python executable
$python_executable = "C:\Users\xxxx\AppData\Local\Programs\Python\Python311\python.exe"

# Specify the path to your Python script
$python_script = "D:\Projects\Python\ocr_file\main.py"

# Construct the command to run the Python script
$command = "$python_executable $python_script"

# Print the command
Write-Host "Command to run Python script: $command"

# Execute the Python script
Invoke-Expression $command

I have the same question (0)
  • MKhan1 Profile Picture
    2 on at

    Had almost the same issue just a while ago.   I have the Anaconda distribution and was able to run my python script  with below 2 steps.  Hope it helps.  To add more details: It opens a power shell window and runs the script. You can add another step to close the window after script has completed running.
    MKhan1_0-1713993022425.png

     

  • Steve48 Profile Picture
    431 on at

    Im not sure how to use this since I dont have Anaconda. Can I use the Run Poweshell Script Action?

  • Verified answer
    Steve48 Profile Picture
    431 on at

    I got it to work with this code and the help of Claude AI

    The python script is running an API that performs OCR. It was getting the API key from a .env (environment variable) file in the same Pycharm project. Powershell didnt work until I hard coded the apikey in the Python script instead of getting it from the .env file/

     

    This is my entry to the Run Powershell Script Dialog.

    $pythonPath = "C:/Users/xxx/AppData/Local\Programs/Python/Python311/python.exe"
    $scriptPath  = "D:/Projects/Python/ocr_file/main.py"
    & "$pythonPath" "$scriptPath"
    Write-Host "Script ran"

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Haque Profile Picture

Haque 605

#2
Valantis Profile Picture

Valantis 340

#3
11manish Profile Picture

11manish 284

Last 30 days Overall leaderboard