-
-
Save ianakelly/2af989602c55f80aaf7f40b8f90d36a9 to your computer and use it in GitHub Desktop.
I ran into this error while trying to run a Python program within Google Cloud Platform (GCP) Virtual Machine (VM). | |
Here is the code section | |
''' python | |
import firebase_admin | |
from firebase_admin import credentials | |
from firebase_admin import firestore | |
''' | |
I received this error when running - | |
'''Traceback (most recent call last): | |
File "Data.py", line 28, in <module> | |
import firebase_admin | |
ImportError: No module named 'firebase_admin' | |
''' | |
To make sure I had the right packages I ran Google Cloud Components and returned this result | |
gcloud components list | |
Your current Cloud SDK version is: 204.0.0 | |
The latest available version is: 207.0.0 | |
┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ | |
│ Components │ | |
├──────────────────┬──────────────────────────────────────────────────────┬──────────────────────────┬───────────┤ | |
│ Status │ Name │ ID │ Size │ | |
├──────────────────┼──────────────────────────────────────────────────────┼──────────────────────────┼───────────┤ | |
│ Update Available │ BigQuery Command Line Tool │ bq │ < 1 MiB │ | |
│ Update Available │ Cloud SDK Core Libraries │ core │ 7.7 MiB │ | |
│ Update Available │ Cloud Storage Command Line Tool │ gsutil │ 3.5 MiB │ | |
│ Update Available │ gcloud Alpha Commands │ alpha │ < 1 MiB │ | |
│ Update Available │ gcloud Beta Commands │ beta │ < 1 MiB │ | |
│ Not Installed │ App Engine Go Extensions │ app-engine-go │ 153.3 MiB │ | |
│ Not Installed │ Cloud Bigtable Command Line Tool │ cbt │ 4.9 MiB │ | |
│ Not Installed │ Cloud Bigtable Emulator │ bigtable │ 4.3 MiB │ | |
│ Not Installed │ Cloud Datalab Command Line Tool │ datalab │ < 1 MiB │ | |
│ Not Installed │ Cloud Datastore Emulator │ cloud-datastore-emulator │ 18.0 MiB │ | |
│ Not Installed │ Cloud Datastore Emulator (Legacy) │ gcd-emulator │ 38.1 MiB │ | |
│ Not Installed │ Cloud Pub/Sub Emulator │ pubsub-emulator │ 33.4 MiB │ | |
│ Not Installed │ Emulator Reverse Proxy │ emulator-reverse-proxy │ 14.5 MiB │ | |
│ Not Installed │ Google Container Local Builder │ container-builder-local │ 4.5 MiB │ | |
│ Not Installed │ Google Container Registry's Docker credential helper │ docker-credential-gcr │ 1.8 MiB │ | |
│ Not Installed │ gcloud app Java Extensions │ app-engine-java │ 118.6 MiB │ | |
│ Not Installed │ gcloud app PHP Extensions │ app-engine-php │ │ | |
│ Not Installed │ gcloud app Python Extensions │ app-engine-python │ 6.1 MiB │ | |
│ Not Installed │ gcloud app Python Extensions (Extra Libraries) │ app-engine-python-extras │ 28.5 MiB │ | |
│ Not Installed │ kubectl │ kubectl │ 14.9 MiB │ | |
└──────────────────┴──────────────────────────────────────────────────────┴──────────────────────────┴───────────┘ | |
I noticed that I was missing gcloud app Python and Python Extentions | |
So I ran the following commands: | |
sudo apt-get install google-cloud-sdk-app-engine-python | |
sudo apt-get install google-cloud-sdk-app-engine-python-extras | |
I reran the Google Cloud Components and saw that I was now up to date with the required components for my project. | |
But when I tried running my project I again ran into the issue of the missing firebase_admin module. | |
The missing ingredient turned out to be pip3 | |
So I ran sudo apt-get install python3-pip | |
and | |
sudo pip3 install firebase_admin | |
and I was off and running! | |
Created with CodePilot.ai |
Hey, I tried running the code but it gives me the same error:
pi@raspberrypi:~/Desktop/pyfirebase $ sudo python triall.py
Traceback (most recent call last):
File "triall.py", line 1, in
import firebase_admin.py
ImportError: No module named firebase_admin.py
I downloaded sudo pip3 install firebase_admin on my raspberry
and here is my code:
import firebase_admin
from firebase_admin import credentials
from firebase_admin import db
cred = credemtials.Certificate('firebase.json')
firebase_admin.initialize_app(cred,{
'databaseURL' : "https://raspberry-pi-197b8.firebaseio.com/"
})
ref = db.reference ('/')
ref.set ({
"employees":{
{"firstName":"John", "LastName" :" Doe"},
{"firstName" :"Anna", "lastName" : "Smith"},
{"firstName" : "Peter", "lastName" : "Jones"}
}
})
thank you in advance
I got TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'