【问题标题】:Autorun python file on reboot using systemd on raspbian在 raspbian 上使用 systemd 重新启动时自动运行 python 文件
【发布时间】: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.

我可以做些什么来修复这个错误?

【问题讨论】:

    标签: python systemd


    【解决方案1】:

    关注此帖:https://www.raspberrypi-spy.co.uk/2015/10/how-to-autorun-a-python-script-on-boot-using-systemd/

    看来 [unit] 和 [service] 应该有一个大写: 所以现在它们变成了 - [Unit] 和 [Service]。

    这可能无关紧要,但可能会改变

    /usr/bin/python3
    

    /usr/bin/python
    

    编辑

    “我会尝试打开 ./.config/lxsession/LXDE-pi/autostart 使用文本编辑器并使用前导“@”添加您的 python 脚本 @python HomeV3.py 您可能需要脚本的路径。” - 感谢 SurferTim - https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=184797

    希望这会有所帮助!

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-31
    • 2017-05-07
    • 2021-11-23
    • 2020-10-28
    • 1970-01-01
    • 2017-03-21
    • 2015-10-25
    • 1970-01-01
    相关资源
    最近更新 更多