I recently wrote a Python program that is designed to communicate via SMPP SMS server.

The issue I'm facing is that I don't know how to run a Python script as a service on my Cent OS server using Conda virtual environment. I'm using a lot of dependencies and choosing virtual environment over Conda is not an option.

Is there any way I could run this script as a service? Also is there a way to write console methods to start this script using the following?

service fooService start

3 Answers 3


Sorry this comes late, but the way to run a python script within a particular environment is to write a shell script like this:

source activate my_env && python my_script.py

and have that wrapper script as your service instead of the python script itself.


There is also another way. You can directly use the python executable from environment in ExecStart like this:

ExecStart=/path/to/conda/envs/my_env_name/bin/python /path/to/executable

For my CentOS server where I'm using miniconda the path is:

ExecStart=/root/miniconda3/envs/test_env/bin/python3 /root/test.py
  • Not sure how to apply this answer. Instead, I am able to run under conda by placing the python executable path directly in the script as the interpreter.
    – skytaker
    May 26, 2022 at 14:58

For git-bash, try the following. The first line inits conda.

eval "$(conda shell.bash hook)"
source activate myenv
python myscript.py

You must log in to answer this question.

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