我一直在关注本教程(https://becominghuman.ai/turn-your-raspberry-pi-into-homemade-google-home-9e29ad220075),完全依赖于我的新树莓派,并不断收到错误消息
Traceback (most recent call last):
File "/home/pi/main.py", line 10, in <module>
import RPi.GPIO as GPIO
ImportError: No module named 'RPi'
我目前有两个文件在教程中列出,一个.py文件读取
#!/usr/bin/env python
from __future__ import print_function
import argparse
import os.path
import json
import google.oauth2.credentials
import RPi.GPIO as GPIO
from google.assistant.library import Assistant
from google.assistant.library.event import EventType
from google.assistant.library.file_helpers import existing_file
GPIO.setmode(GPIO.BCM)
GPIO.setup(25, GPIO.OUT)
def process_event(event):
"""Pretty prints events.
Prints all events that occur with two spaces between each new
conversation and a single space between turns of a conversation.
Args:
event(event.Event): The current event to process.
"""
if event.type == EventType.ON_CONVERSATION_TURN_STARTED:
print()
GPIO.output(25,True)
print(event)
if (event.type == EventType.ON_CONVERSATION_TURN_FINISHED and
event.args and not event.args['with_follow_on_turn']):
print()
GPIO.output(25,False)
def main():
parser = argparse.ArgumentParser(
formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('--credentials', type=existing_file,
metavar='OAUTH2_CREDENTIALS_FILE',
default=os.path.join(
os.path.expanduser('/home/pi/.config'),
'google-oauthlib-tool',
'credentials.json'
),
help='Path to store and read OAuth2 credentials')
args = parser.parse_args()
with open(args.credentials, 'r') as f:
credentials = google.oauth2.credentials.Credentials(token=None,
**json.load(f))
with Assistant(credentials) as assistant:
for event in assistant.start():
process_event(event)
if __name__ == '__main__':
main()
另一个是.sh文件读取中的几行代码
#!/bin/sh
/home/pi/env/bin/python3 -u /home/pi/main.py
非常感谢任何帮助或建议
答案 0 :(得分:0)
我刚刚完成了相同的教程。我认为问题与设置python环境有关。我确信我的解决方案并不是最优雅的,但它可以使设置正常工作!
首先,我运行了以下内容(而不是第4步中的最后一个命令)
sudo pip3 install --upgrade google-assistant-library
然后在步骤6中,我运行以下命令代替他使用的相应命令
sudo pip3 install --upgrade google-auth-oauthlib[tool]
google-oauthlib-tool --client-secrets "PATH_TO_YOUR_JSON_FILE" --scope https://www.googleapis.com/auth/assistant-sdk-prototype --save --headless
最后我将shell脚本更改为以下
#!/bin/sh
python3 -u /home/pi/main.py
希望这可以提供帮助!