【问题标题】:Firebase import module fails with ModuleNotFoundError: No module named 'Crypto'Firebase 导入模块失败并出现 ModuleNotFoundError: No module named 'Crypto'
【发布时间】:2022-01-09 10:47:01
【问题描述】:

我正在尝试启动我编写的脚本,该脚本应该从 firebase db 读取数据,但它会引发以下错误:

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'

我尝试通过以下方式安装 Crypto:

pip3 install Crypto
pip3 install pycryptodome

当我运行pip3 show Crypto 时,我得到以下输出:

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: git.simpkins@gmail.com
License: MIT license
Location: /Users/georgeoprea/Library/Python/3.8/lib/python/site-packages
Requires: Naked, shellescape
Required-by: 

这是我在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

操作系统信息:macOS 12.1M1 Pro 上运行。

如何让我的脚本识别Crypto 模块?

【问题讨论】:

    标签: python firebase module


    【解决方案1】:

    这可能与this question有些相关。

    /e: 好的,既然您使用的是this firebase package,我希望能帮助您。 首先,它没有运行是包的错。虽然它依赖于许多外部包,但它没有定义它们。 这就是我必须在干净的虚拟环境中做的事情才能做到from firebase import Firebase

    pip install sseclient python_jwt gcloud pycryptodome requests-toolbelt
    

    Here 是我在干净环境中最终得到的 requirements.txt。请注意,这仅用于从包中导入单个类。可能还有其他依赖隐藏在某个地方,等待抛出异常。

    我鼓励您就此问题向开发者提供反馈。更好的是,自己解决这个问题并打开一个拉取请求。您可能会帮助其他人解决同样的问题。

    【讨论】:

    • 我按照您的建议检查了该线程,并尝试了那里的建议。虽然没有运气。我正在使用的 firebase 模块是这个:` 名称:firebase 版本:3.0.1 摘要:Google 的 Firebase REST API 主页的 Python 接口:bitbucket.org/joetilsed/firebase 作者:Joe Tilsed 作者电子邮件:Joe@Tilsed。 com 许可证:未知位置:/Users/georgeoprea/Library/Python/3.8/lib/python/site-packages 要求:请求要求:`我在卸载 Crypto 后尝试了 pycrypto 和 pycryptodome。它没有用。 firebase 需要加密货币。我有加密货币
    【解决方案2】:

    我找到了解决方法。我只是使用另一个模块从 firebase db 中读取。我没有使用firebase,而是使用firebase_admin,如firebase documentation 中所述。 firebase_admin 不使用 Crypto 所以从这个角度来看没有更多的问题。但是我不得不稍微改变一下我检索和写入数据的方式。

    【讨论】:

    • 您能否提供更多详细信息,说明您需要对读取和写入数据的方式进行更改?这可能对未来有类似问题的读者有用。
    猜你喜欢
    • 2022-08-19
    • 1970-01-01
    • 1970-01-01
    • 2020-08-18
    • 2020-10-03
    • 1970-01-01
    • 2022-11-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多