2017-09-25 83 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

相關問題