将所有python脚本文件作为sudo运行

时间:2015-08-27 22:02:37

标签: python linux sudo

我正在尝试将python脚本作为sudo运行。容易:

sudo python main.py

但是这个文件调用另一个文件:

import getdata

getdata调用包:

import spidev

# Establish SPI device on Bus 0,Device 0
# need sudo rights!
spi = spidev.SpiDev()
spi.open(0,0)

但是当我以sudo的身份运行我的脚本时,我得到了:

[Thu Aug 27 23:56:16 2015] [error] [client 192.168.1.31] Premature end of script headers: main.py, referer: http://192.168.1.50/moisture/
Traceback (most recent call last):
  File "/var/www/moisture/main.py", line 13, in <module>
    import twitter
  File "/var/www/moisture/twitter.py", line 7, in <module>
    import getdata
  File "/var/www/moisture/getdata.py", line 14, in <module>
    spi.open(0,0)
IOError: [Errno 13] Permission denied

如何将所有文件作为sudo运行?

0 个答案:

没有答案