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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.