2014-10-04 158 views
1

我有我的RPI一个python脚本,需要在引导自动开机启动python脚本(RPI)

我添加它rc.local中运行,并用它做工精细

一前几天,我加入到该程序的功能,并且它现在使用的open()我每次重启丕时间阅读txt文件

现在,蟒蛇给我和错误:

File "home/pi/client.py", line 13, in <module> 
    stats=open('stats.txt') 
IOError: [Errno 2] No such file or directory: 'stats.txt' 

当我手动启动scri点与:

sudo python client.py 

它工作正常,没有问题。

有什么建议吗?

回答

0

您的rc.local可能无法在正确的目录中启动您的脚本。所以,你应该:

  • 使用类似cd my/dir && python /path/to/home/pi/client.py
  • 通话os.chdir("/path/to/some_dir")在脚本
  • 在打开文件时使用绝对路径:stats = open('/path/to/stats.txt')
+0

使用你的工作第三bulletpoint – 2014-10-04 21:14:09

+0

!感谢芽! (按回车在此之前发表评论:() – 2014-10-04 21:14:58