While testing out firebase function with python i notice that there are some package that unable to import. It simple cause a No module named error.
Some Package that cause this error are pytz and dateutil.
I’m working under firebase emulator.
Following official guideline.
And both package are included in requirements.txt with specific version and file is in same director as main.py.
All the code are written on main.py and issue causing it is also in main.py.
if I’m lacking any information please let me know.
I found two similar questions from Stack Overflow that may relate to your case. Although the answers are over a year older, they could still be relevant to your situation.
According to jvhang’s answer to this question, this is a known issue back then which has since been patched and merged to main. Here’s the workaround he suggested:
import sys
from pathlib import Path
sys.path.insert(0, Path(__file__).parent.as_posix())
from test import base
For more details, see jvhang’s answer to the question: Firebase python cloud function is unable to import local package.
Here’s the other workaround suggested by witi:
-
Delete the
venv
folder created byfirebase init functions
. -
Create a new one as follows:
python3.11 -m venv venv
source venv/bin/activate
pip3 install --upgrade pip
python3.11 -m pip install -r requirements.txt
- Now deploy with
firebase deploy --only functions
Full details of witi’s response: Firebase Cloud Functions Python – Cannot Add Dependencies.
Kiko Zamora xWF is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.