问题描述
---问题已结束
这是我的错误,我的uWSGI启动脚本切换到了另一个virtualenv.
It was my mistake, my uWSGI startup script switches to a different virtualenv.
---原始问题
我正在尝试将Flask应用服务器中的推送通知发布到Android APP.
I'm trying to publish push notifications from my Flask app server to Android APP.
服务器环境(dev):
Server environment (dev):
- Mac OS Sierra
- 烧瓶1.0.2
- Python 3.6.5
- firebase-admin SDK 2.17.0(最新版本)
将代码作为Flask应用程序运行以初始化SDK时,import语句会引发错误:
When running code as Flask application for initialising the SDK, import statement throws error:
import firebase_admin
但是,在Python解释器模式下的import语句之上运行不会产生任何错误. PyCharm还能够识别firebase_admin
模块.这三种设置(Flask应用程序,解释器,PyCharm)都使用相同的virtualenv.
However, running above import statement from Python interpreter mode gives no error. PyCharm is also able to recognize the firebase_admin
module. All three setups (Flask app, interpreter, PyCharm) use the same virtualenv.
我尝试了一些较旧的SDK版本,但错误仍然存在.有任何线索吗?
I had tried few older versions of SDK but error persists. Any clue?
---更多详细信息
该模块是使用pip install firebase-admin
命令从virtualenv中的命令行安装的.
The module was installed from command line within virtualenv using command pip install firebase-admin
.
在同一virtualenv中从命令行以Flask + uWSGI应用程序运行代码时发生错误. pip freeze
表明该模块确实存在.
The error occurs when running the code as Flask+uWSGI app from command line, within the same virtualenv. pip freeze
shows that the module is indeed present.
---问题已结束
这是我的错误,我的uWSGI启动脚本切换到了另一个virtualenv.
It was my mistake, my uWSGI startup script switches to a different virtualenv.
推荐答案
如何将firebase_admin
软件包安装/添加到项目中?
How did you install/add the firebase_admin
package to your project?
如果您未明确安装/添加软件包,则只遇到了少数情况(可能还有其他情况/解决方案),这会产生错误ModuleNotFoundError: No module named 'firebase_admin'
:
If you haven't explicitly installed/added the package, I've only come across a few cases (there may be other cases/solutions as well), that gives off the error ModuleNotFoundError: No module named 'firebase_admin'
:
如果使用PyCharm,则可以从PyCharm偏好设置中安装/添加它
If using PyCharm, you can install/add it from the PyCharm preferences
- 文件>首选项>项目>项目解释器
- 单击添加"按钮,搜索firebase,选择适当的程序包:
firebase-admin
- 单击安装软件包"按钮.
我使用Visual Studio Code,并选择使用保存在根目录中的requirements.txt
文件将firebase_admin
库安装到virtualenv中.即使您使用的是PyCharm,您仍然可以使用此方法:
I use Visual Studio Code, and opted to install firebase_admin
libraries into the virtualenv using a requirements.txt
file saved in the root directory. You can still use this method even if you're using PyCharm:
1)激活您的环境
2)创建具有以下内容的requirements.txt
文件:
2) Create a requirements.txt
file with the following contents:
firebase_admin
// other packages
3)运行pip install
pip install -r requirements.txt
4)安装后,可以通过检查以下目录中的site-packages
文件夹来确认该文件已经可用:
4) After installing, you can confirm that's already available by checking the site-packages
folder in the following directory:
env/lib/site-packages/firebase_admin
env/lib/site-packages/firebase_admin-<version>.dist-info
5)尝试再次运行代码.
5) Try running the code again.
希望有帮助!
这篇关于带有Flask的Firebase Admin SDK引发错误没有名为"firebase_admin"的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!