jee_kuu
jee_kuu

Reputation: 35

Firebase import module fails with ModuleNotFoundError: No module named 'Crypto'

I am trying to launch a script I wrote that is supposed to read data from a firebase db but it throws the following error:

Traceback (most recent call last):
  File "myScript.py", line 8, in <module>
    from firebase import Firebase
  File "/Users/georgeoprea/Library/Python/3.8/lib/python/site-packages/firebase/__init__.py", line 20, in <module>
    from Crypto.PublicKey import RSA
ModuleNotFoundError: No module named 'Crypto'

I have tried to install Crypto in the following ways:

pip3 install Crypto
pip3 install pycryptodome

When I run pip3 show Crypto I get the following output:

Name: crypto
Version: 1.4.1
Summary: Simple symmetric GPG file encryption and decryption
Home-page: https://github.com/chrissimpkins/crypto
Author: Christopher Simpkins
Author-email: [email protected]
License: MIT license
Location: /Users/georgeoprea/Library/Python/3.8/lib/python/site-packages
Requires: Naked, shellescape
Required-by: 

This is the list of imports I have in myScript.py:

from bs4 import BeautifulSoup
import time
import smtplib
from datetime import datetime
import json
import random
from email.message import EmailMessage
from firebase import Firebase

OS info: macOS 12.1 running on M1 Pro.

What could I do to have my script recognise the Crypto module?

Upvotes: 2

Views: 1316

Answers (2)

jee_kuu
jee_kuu

Reputation: 35

I found a workaround for this. I simply used another module to read from the firebase db. Instead of using firebase I used firebase_admin as mentioned in the firebase documentation. firebase_admin doesn't use Crypto so there's no more problem from this point of view. However I had to change a little bit how I retrieve and write data.

Upvotes: 0

mc51
mc51

Reputation: 2277

This might be somewhat related to this question.

/e: Ok, since you are using this firebase package, I can hopefully help you out. First of all, it's the package's fault that it isn't running. While it depends on many external packages, it has none of them defined. This is what I had to do in a clean virtual environment just to be able to do from firebase import Firebase:

pip install sseclient python_jwt gcloud pycryptodome requests-toolbelt

Here is the requirements.txt I ended up with in the clean environment. Notice, that this was only for importing a single class from the package. There still might be other dependencies hidden somewhere, waiting to throw an exception.

I encourage you to give feedback to the developer about this issue. Even better, fix this yourself and open a Pull Request. You might help others with the same issue.

Upvotes: 1

Related Questions