gpt4 book ai didi

python - 导入错误 : cannot import name 'opentype'

转载 作者:太空狗 更新时间:2023-10-29 22:00:11 27 4
gpt4 key购买 nike

我正在尝试按照在 Raspberry Pi 2 B+ 上运行的 py 代码中使用 Firebase 的说明进行操作。在 python 3 上运行时,会发生不好的事情。

我已经在我的脚本中包含了 pyrebase,但是当我使用 python3 运行它时,我得到了以下信息(请参见下文)。我一直在研究各种其他语言,但我只是选择了 python 和 Raspberry Pi 用于我想到的项目。

这篇文章将包含我的代码和运行代码时得到的终端输出

我的代码:

#import Libraries
import RPi.GPIO as GPIO
import time
import pyrebase
import os

#Firebase Configuration
config = {
"apiKey": "apiKey",
"authDomain": "rpitest-xxxxx.firebaseapp.com",
"databaseURL": "rpitest-xxxxx.firebaseio.com",
"storageBucket": "rpitest-xxxxx.appspot.com"
}

firebase = pyrebase.initialize_app(config)

#GPIO Setup
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(22, GPIO.OUT)

#Firebase Database Intialization
db = firebase.database()

#While loop to run until user kills program
while(True):
#Get value of LED
led = db.child("led").get()

#Sort through children of LED(we only have one)
for user in led.each():
#Check value of child(which is 'state')
if(user.val() == "OFF"):
#If value is off, turn LED off
GPIO.output(22, False)
else:
#If value is not off(implies it's on), turn LED on
GPIO.output(22, True)

#0.1 Second Delay
time.sleep(0.1)

命令:

    pi@raspberrypi:~/Desktop/LearnPython $ sudo python3 IoTLED.py

输出:

    pi@raspberrypi:~/Desktop/LearnPython $ sudo python3 IoTLED.py
Traceback (most recent call last):
File "IoTLED.py", line 4, in <module>
import pyrebase
File "/usr/local/lib/python3.5/distpackages/pyrebase/__init__.py", line 1, in <module>
from .pyrebase import initialize_app
File "/usr/local/lib/python3.5/distpackages/pyrebase/pyrebase.py", line 17, in <module>
from oauth2client.service_account import ServiceAccountCredentials
File "/usr/local/lib/python3.5/dist-packages/oauth2client/service_account.py", line 26, in <module>
from oauth2client import crypt
File "/usr/local/lib/python3.5/dist-packages/oauth2client/crypt.py", line 23, in <module>
from oauth2client import _pure_python_crypt
File "/usr/local/lib/python3.5/dist-packages/oauth2client/_pure_python_crypt.py", line 24, in <module>
from pyasn1_modules.rfc2459 import Certificate
File "/usr/local/lib/python3.5/dist-packages/pyasn1_modules/rfc2459.py", line 20, in <module>
from pyasn1.type import opentype
ImportError: cannot import name 'opentype'

我的怀疑:

我怀疑 opentype 库丢失了。

结束语:

我真的真的真的被困在这一点上超过一天了。我需要帮助。非常感谢,非常感谢您的帮助。

最佳答案

我遇到了类似的问题,这为我解决了:

pip install --upgrade google-auth-oauthlib

看起来 google-auth-oauthlib 依赖项在我的设置中已过时。 requirements.txt ( https://github.com/google/aiyprojects-raspbian/blob/voicekit/requirements.txt ) 中的版本是 0.1.0。我使用的是语音套件,但同样适用于您的设置。

有关更多详细信息,请参阅此问题:ImportError: cannot import name 'opentype' on new installation

另请参阅树莓派论坛:https://www.raspberrypi.org/forums/viewtopic.php?f=114&t=198933&p=1241439#p1241439

关于python - 导入错误 : cannot import name 'opentype' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47600597/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com