skip to Main Content

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


  1. Prefix a dot to the module name which signifies a local module:

    from .localpackage.constants import *
    
    Login or Signup to reply.
  2. 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:

    import sys
    from pathlib import Path
    
    sys.path.insert(0, Path(__file__).parent.as_posix())
    
    from test import base
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search