I try to deploy a firebase cloud function via Firebase cli.
My folder structure is:
functions
|--localpackage
| |-__init__.py
| |-constants.py
|-main.py
|-requirements.txt
An I try to import constants.py
via from localpackage.constants import *
. I guess thats the way it’s supposed to work. Source https://firebase.google.com/docs/functions/get-started?hl=de&gen=2nd#python-preview_3 refers to https://cloud.google.com/functions/docs/writing/specifying-dependencies-python?hl=de.
Problem:
As soon as i want to deploy the function via firebase deploy --only functions
, i get the error:
from localpackage.constants import *
ModuleNotFoundError: No module named 'localpackage'
Local test deploy via functions-framework --target testPy --debug
works just fine.
I tried to change paths and import statements but nothing worked.
2
Answers
Prefix a dot to the module name which signifies a local module:
This is a known issue that was patched and merged to main last week but not yet pushed out to PyPi.
If you prefer not to reference the github repo in your dependencies, here’s the work-around: