0

I'm trying to make a SSMS (SQL Server) job step, which calls a python script to execute through powershell - but instead of using the SQL integrated Python, I want to use a Python environment that is installed on the server.

Instead of the usual command python "D:\path\script.py", I'm first trying to activate a Conda environment and then executing the python script like this: conda activate environment; python "D:\path\script.py"

If I run the above command in powershell on the server, with the agent account that runs the script through SSMS, it goes through successfully.

If I set the same command on the job step and run the job, I get the the same output as if I didn't activate the environment beforehand (If I just executed the script, without first activating the environment).

Is this possible or do I have to find another way to execute this script?

This is how I have my step set up:

enter image description here

An alternative solution I found is to create a ps1 file with the text conda activate environment; "D:\path\script.py", and then call the ps1 file in the job step.

This works but I'd like to execute it directly through a job step if possible.

ire
  • 491
  • 2
  • 12
  • 26
  • 1
    Maybe this can help: [subprocess - Best way to execute a python script in a given conda environment - Stack Overflow](https://stackoverflow.com/questions/42025173/best-way-to-execute-a-python-script-in-a-given-conda-environment) – DocZerø Mar 21 '22 at 08:40
  • @DocZerø conda run works! Thank you very much. If you write it as an answer and I'll accept. So `conda run -n environment python D:\path\script.py` – ire Mar 21 '22 at 11:56

0 Answers0