简体   繁体   English

作为ubuntu服务运行时,Python脚本给出错误

[英]Python script gives error when running as a ubuntu service

I have set up a service, and when I run it, I get the following error: 我已经设置了服务,当我运行它时,出现以下错误:

 ImportError: No module named httplib2

I have httplib2 installed with pip and my systemd ExecStart command is like this: 我已经用pip安装了httplib2,而我的systemd ExecStart命令是这样的:

ExecStart=/usr/bin/python /home/orionas/Desktop/quickstart.py

The same script runs perfect from command line. 相同的脚本可从命令行完美运行。

嗯,我想您可能已经在您的用户下安装了httplib2,但是systemd使用另一个用户来运行quickstart脚本。

Under [Service] include a line "User=" The python script will then inherit the permissions and paths of that user AFAIK. 在[服务]下,添加一行“ User =”,然后python脚本将继承该用户AFAIK的权限和路径。

Note: It is probably Not recommended to run a systemd service with userid the same as yours. 注意:可能不建议使用与您的用户名相同的用户ID运行systemd服务。 Potential security risk. 潜在的安全风险。 Another possible solution would be to run the python script within a [virtualenv] http://docs.python-guide.org/en/latest/dev/virtualenvs/ Many people do this and as far as I know it's the recommended practise 另一种可能的解决方案是在[virtualenv] http://docs.python-guide.org/zh-CN/latest/dev/virtualenvs/中运行python脚本,据我所知,这是推荐的做法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM