Description
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:##
-
create "blank workspace"
-
run firebase init functions-> that create "functions" folder as it should but no "vevn" is created (and because of that no dependecies are installed)-> not case for the guy in this video :/ -> https://www.youtube.com/watch?v=mvEHYMsk_AE&t=202s
-
cd functions ->
python3 -m venv venv
-> pick "python3" in list (as sugest by gemini) -> instalation completed -
adding "pkgs.python3" to dev.nix -> packeges
-
test runing
firebase init
again to install missing dependecies (now when I have venv in functions) but getting error: Requirement already satisfied: pip in ./venv/lib/python3.11/site-packages (24.0)
/bin/sh: line 1: python3.12: command not found -
so bc of that I go to dev.nix and change in packages from "pkgs.python3" to "pkgs.python312" (keep in mind that docs says that python 3.10 and 3.11 are supported)
-
run firebase init again and only now all the dependecies are installed
-
I can now deploy functions as well
BUT let's say that I want to addnumpy
library to project: -
when in "/functions" directory :
source venv/bin/activate
-
pip install numpy -> python311Packages.pip
-
import numpy to the project, ex:
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!")
- run firebase deploy, now I get this error (bc I changed to python312 in packages??):
[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:/ )