Dav*_*wan 4 python services start-stop-daemon virtualenv datascience-anaconda
我最近编写了一个 Python 程序,旨在通过 SMPP SMS 服务器进行通信。
我面临的问题是我不知道如何使用 Conda 虚拟环境在 Cent OS 服务器上将 Python 脚本作为服务运行。我使用了很多依赖项,在 Conda 上选择虚拟环境不是一种选择。
有什么办法可以将此脚本作为服务运行吗?还有一种方法可以使用以下方法编写控制台方法来启动此脚本吗?
service fooService start
Run Code Online (Sandbox Code Playgroud)
小智 5
抱歉,这来晚了,但是在特定环境中运行 python 脚本的方法是编写这样的 shell 脚本:
#!/bin/bash
source activate my_env && python my_script.py
Run Code Online (Sandbox Code Playgroud)
并将该包装脚本作为您的服务而不是 python 脚本本身。
小智 5
还有另一种方法。您可以直接使用环境中的 python 可执行文件,ExecStart
如下所示:
ExecStart=/path/to/conda/envs/my_env_name/bin/python /path/to/executable
Run Code Online (Sandbox Code Playgroud)
对于我使用 miniconda 的 CentOS 服务器,路径是:
ExecStart=/root/miniconda3/envs/test_env/bin/python3 /root/test.py
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
16257 次 |
最近记录: |