3

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

returns:

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
    I assume simulate is an executable connected to Python. So have you tried providing a full path to the executable?
    – Ramhound
    Commented Feb 16, 2022 at 17:16
  • That seems to have solved that issue, thanks. Out of interest, why can't the script "see" the same executable as the command prompt?
    – ocelto
    Commented Feb 16, 2022 at 18:04
  • You should submit a detailed answer explaining what exactly resolved your issue.
    – Ramhound
    Commented Feb 16, 2022 at 19:49

2 Answers 2

2

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"';

Supporting Resources

0

Replacing simulate "abcd" by C:\path\to\script\simulate.exe "abcd" inside the poweshell script resolved my issue.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .