2017-09-25 91 views
0

我想在使用systemd重新启动时自动运行python文件。我尝试使用systemd的原因是因为我的python文件需要网络连接并在该时间点可用,并且/ home/pi目录需要准备好使用并且系统时间已由NTP更新继续。 但是我收到以下错误,当我尝试启动脚本:重启后使用systemd在raspbian上自动运行python文件

systemctl start mysript.service 

无法启动myscript.service:单位myscript.service未能 负载:无效的参数。有关详细信息,请参阅系统日志和'systemctl状态 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. 

我该如何解决这个错误?

回答

0

下面这篇文章:https://www.raspberrypi-spy.co.uk/2015/10/how-to-autorun-a-python-script-on-boot-using-systemd/

看来,[单位]和[服务]应该有他们的资本: 所以现在他们成为 - [单位]和[服务]。

这可能是irrevelant但也许改变

/usr/bin/python3 

/usr/bin/python 

编辑

“我会尝试开放./.config/lxsession/LXDE-pi/使用文本编辑器自动启动 ,并将您的Python脚本添加一个前导'@' @python HomeV3.py 您可能需要脚本路径。“ - Credit to SurferTim - https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=184797

希望这会有所帮助!

+0

编辑我的帖子有新错误,请帮忙! –

+0

编辑我的答案 – Ben10

+0

如果这没有帮助 - 看看这个:http://www.raspberry-projects。在“设置应用程序”下的com/pi/pi-operating-systems/raspbian/auto-running-programs-gui – Ben10

相关问题