导入错误:无法导入名称' opentype'

时间:2017-12-01 19:54:38

标签: python python-3.x firebase raspberry-pi

我试图按照在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库缺失了。

结束备注:

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

2 个答案:

答案 0 :(得分:26)

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

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

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

答案 1 :(得分:12)

你也可以尝试一下。它对我有用。

pip install --upgrade pyasn1-modules