Call a python package from powershell script
I have a conda environment activated in the powershell command prompt. I have a python package that has been installed with pip:
pip install -e .which installs my package with an entry point simulate. It works fine when called from the powershell command prompt:
simulate "abcd"When I try to call it from within a powershell script it cannot be found.
powershell.exe .\run.ps1returns:
simulate : The term 'simulate' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct
and try again.
At C:\path\to\script\run.ps1:1 char:1
+ simulate "abcd"
+ ~~~~~~~ + CategoryInfo : ObjectNotFound: (nwsetup:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException 3 1 Answer
Use Start-Process and its -ArgumentList option to execute the python command (or script) passing it the argument value the actual python command (or script) expects. Set the -FilePath parameter to be the full path to the python.exe file on Windows.
PowerShell
Start-Process -FilePath "C:\Program Files\Python\python.exe" -ArgumentList 'simulate "abcd"';or call a python script
Start-Process -FilePath "C:\Program Files\Python\python.exe" -ArgumentList '"c:\scripts\simulate.py" "abcd"';