Tony Alfonse

02/23/2023, 11:32 PM
Hey Everyone! How can I set up prefect service in Linux within a conda environment? I created this shell file:
eval "$(conda shell.bash hook)"
conda activate ETL
prefect server start
And created this systemd service:


Whenever I run the shell script locally, it works but whenever the systemd service triggers it, it throws this error:
prefect_service.service - Prefect
     Loaded: loaded (/etc/systemd/system/prefect_service.service; enabled; vendor preset: enabled)
     Active: inactive (dead) since Thu 2023-02-23 23:29:43 UTC; 3s ago
    Process: 2233 ExecStart=/home/zeephremia/files_required/ (code=exited, status=0/SUCCESS)
   Main PID: 2233 (code=exited, status=0/SUCCESS)

Feb 23 23:29:43 linux-server systemd[1]: Started Prefect.
Feb 23 23:29:43 linux-server[2233]: Starting the script...
Feb 23 23:29:43 linux-server[2234]: /home/zeephremia/files_required/ line 5: conda: command not found
Feb 23 23:29:43 linux-server[2235]: /home/zeephremia/files_required/ line 6: conda: command not found
Feb 23 23:29:43 linux-server[2237]: /home/zeephremia/files_required/ line 7: prefect: command not found
Feb 23 23:29:43 linux-server[2233]: Script completed.
Feb 23 23:29:43 linux-server systemd[1]: prefect_service.service: Succeeded.
Would really appreciate any help, thank you! 🙂

Ryan Peden

02/24/2023, 2:28 AM
I think that instead of writing the initiate script, in the
section you could do something like:
ExecStart=/home/myuser/.conda/envs/my_env/bin/prefect server start
The executable script that gets generated when you install Prefect in a conda environment should automatically use the Python installation for that environment even if that env isn't currently activated.