【发布时间】:2018-03-05 23:05:43
【问题描述】:
我正在尝试使用 systemd 在重新启动时自动运行 python 文件。我尝试使用 systemd 的原因是因为我的 python 文件需要在那个时间点连接并可用网络,并且 /home/pi 目录需要准备好使用并且系统时间已由 NTP 更新继续。 但是,当我尝试启动脚本时收到以下错误:
systemctl start mysript.service
启动 myscript.service 失败:单元 myscript.service 未能启动 负载:无效的参数。查看系统日志和'systemctl status myscript.service' 了解详情。
systemctl status myscript.service
myscript.service 已加载:错误(原因:参数无效) 活动不活动(死)
myscript.service 缺少 ExecStart 设置。拒绝。
以下是 myscript.service:
[unit]
Description=MyPythonFile
After=multi-user.target
[service]
Type=idle
ExecStart=/usr/bin/python3 /home/pi/mypythonfile/file.py
[Install]
WantedBy=multi-user.target
有人知道我为什么会收到这个错误吗?
[[编辑]] 引用了这篇文章:https://www.raspberrypi-spy.co.uk/2015/10/how-to-autorun-a-python-script-on-boot-using-systemd/
现在可以加载服务,但是我收到一个错误,因为我的 python 程序正在使用 Tkinter。
_tkinter.TclError: couldn't connect to display "0.0"
myscript.service: main process exited, code=exited, status=1/FAILURE
Unit myscript.service entered failed state.
我可以做些什么来修复这个错误?
【问题讨论】: