firebase / firebase-functions-python

Apache License 2.0
129 stars 22 forks source link

setting up firebase-functions with Python #206

Open neo-xy opened 2 weeks ago

neo-xy commented 2 weeks ago

For the love of anything that is holy and unholy can anyobdy explain how correctly to set up firebase-functions with Python?! 😀😭 (tested everything that I found on stackoverflow and chatGpt/gemini to set it up but one error just leads to another and I just spinning in the circles for 3 days now -.-) At this point I abandon to build it localy and trtying to use "project idx" instead (as my local envirment is trash at this point after all AI sugestions).

my current steps:

from firebase_functions import https_fn
from firebase_admin import initialize_app
import numpy as np

initialize_app()

https_fn.on_request()
def on_request_example(req: https_fn.Request) -> https_fn.Response:
    np.random.seed(42)
    return https_fn.Response("Hello world!")

[2024-06-16 11:54:11,957] ERROR in app: Exception on /__/functions.yaml [GET] Traceback (most recent call last): File "/home/user/zzz/functions/venv/lib/python3.12/site-packages/flask/app.py", line 1473, in wsgi_app response = self.full_dispatch_request() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/user/zzz/functions/venv/lib/python3.12/site-packages/flask/app.py", line 882, in full_dispatch_request rv = self.handle_user_exception(e) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/user/zzz/functions/venv/lib/python3.12/site-packages/flask/app.py", line 880, in full_dispatch_request rv = self.dispatch_request() ^^^^^^^^^^^^^^^^^^^^^^^ File "/home/user/zzz/functions/venv/lib/python3.12/site-packages/flask/app.py", line 865, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/user/zzz/functions/venv/lib/python3.12/site-packages/firebase_functions/private/serving.py", line 122, in get_functions_yaml functions = get_functions() ^^^^^^^^^^^^^^^ File "/home/user/zzz/functions/venv/lib/python3.12/site-packages/firebase_functions/private/serving.py", line 40, in get_functions spec.loader.exec_module(module) File "", line 995, in exec_module File "", line 488, in _call_with_frames_removed File "/home/user/zzz/functions/main.py", line 7, in import numpy as np ModuleNotFoundError: No module named 'numpy'

127.0.0.1 - - [16/Jun/2024 11:54:11] "GET /__/functions.yaml HTTP/1.1" 500 -

127.0.0.1 - - [16/Jun/2024 11:54:11] "GET /__/quitquitquit HTTP/1.1" 200 -

Error: Functions codebase could not be analyzed successfully. It may have a syntax or runtime error

then I tested some things to fix that error (founded on stackoverflow and AIs but nothing helped/leaded to som eother errors) It's just like there is no wining with this s*** 😫

(please keep in mind that I'm not a python developer and for all Python pros that is maybe a silly fix-although I ask some of my colleagues that code in python and they could not fix it for me:/ )

google-oss-bot commented 2 weeks ago

I found a few problems with this issue:

exaby73 commented 2 weeks ago

Hello @neo-xy. Have you followed the instructions here?

neo-xy commented 2 weeks ago

Hi @exaby73 yes, I did - and the big thing that is missing there (that I noticed just yesterday) is that one have to run pip freeze -> requirements.txt FROM /fanctions directory before firebase deploy- which is missing in documentation (at least of what can I see). at the same time so still don't understand why "firebase init" in the attached youtube video creates "venv" but when I run it it does not ....

exaby73 commented 3 days ago

I see the venv folder being generated under functions/venv on running firebase init and choosing Python. I'm using version 13.11.4 of the CLI. Make sure you have your CLI updated by running npm install -g firebase-tools@latest