我正在为我的Raspberry Pi安装一个温度传感器并遇到了这个问题。为了运行代码中指定的驱动程序,我不得不运行它是一个shell命令。我很难搞清楚为什么我的语法不正确。
代码:
def read_dht22( PiPin ):
output = subprocess.check_output([shell=True], ['/home/pi/Adafruit-Raspberry-Pi-Python-Code/Adafruit__DHT_Driver", "2302", str(PiPin)])
错误:
sudo python scr6.py
File "scr6.py", line 31
output = subprocess.check_output([shell=True], ['/home/pi/Adafruit-Raspberry-Pi-Python-Code/Adafruit_DHT_Driver', '2302', str(PiPin)])
^
SyntaxError: invalid syntax
添加shell之前的错误= True
sudo python scr5.py
Traceback (most recent call last):
File "scr5.py", line 46, in <module>
temp_c, temp_f = read_dht22(4)
File "scr5.py", line 31, in read_dht22
output = subprocess.check_output(["/home/pi/Adafruit-Raspberry-Pi-Python-Code/Adafruit_DHT_Driver", "2302", str(PiPin)])
File "/usr/lib/python2.7/subprocess.py", line 537, in check_output
process = Popen(stdout=PIPE, *popenargs, **kwargs)
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1259, in _execute_child
raise child_exception
OSError: [Errno 13] Permission denied
答案 0 :(得分:0)
这应该可以解决您的语法错误:
def read_dht22( PiPin ):
output = subprocess.check_output(["/home/pi/Adafruit-Raspberry-Pi-Python-Code/Adafruit__DHT_Driver", "2302", str(PiPin)], shell=True)