I'm trying to follow the instructions for utilizing Firebase in my py code running on Raspberry Pi 2 B+. While running on python 3, bad stuff happens.
I have included the pyrebase in my script but when I run it using python3 I get following instead (see below please). I have been working on various other languages but I just picked python and Raspberry Pi for a project that I had in mind.
This post will have both my code and the terminal output that I get when I run the code
#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'
I suspect the opentype library is missing.
I am really really really stuck at this point for more than a day now. I need help. Thank you so much and I really appreciate your help.
I had a similar problem, and this fixed it for me:
pip install --upgrade google-auth-oauthlib
It looks like the google-auth-oauthlib dependency was out of date in my setup. The version in the requirements.txt (https://github.com/google/aiyprojects-raspbian/blob/voicekit/requirements.txt) was 0.1.0. I was using the voice kit, but the same could apply to your set up.
For more details see this question: ImportError: cannot import name 'opentype' on new installation
Also see this on the raspberry pi forum: https://www.raspberrypi.org/forums/viewtopic.php?f=114&t=198933&p=1241439#p1241439
You can try this also. It worked for me.
pip install --upgrade pyasn1-modules
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With