Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setting up firebase-functions with Python #206

Open
neo-xy opened this issue Jun 16, 2024 · 4 comments
Open

setting up firebase-functions with Python #206

neo-xy opened this issue Jun 16, 2024 · 4 comments
Labels
waiting for customer response Issue is on hold awaiting more information from OP

Comments

@neo-xy
Copy link

neo-xy commented Jun 16, 2024

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 add numpy 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:/ )

@google-oss-bot
Copy link

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

@exaby73 exaby73 transferred this issue from firebase/firebase-functions Jun 17, 2024
@exaby73
Copy link
Contributor

exaby73 commented Jun 17, 2024

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

@exaby73 exaby73 added the waiting for customer response Issue is on hold awaiting more information from OP label Jun 17, 2024
@neo-xy
Copy link
Author

neo-xy commented Jun 17, 2024

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
Copy link
Contributor

exaby73 commented Jul 1, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for customer response Issue is on hold awaiting more information from OP
Projects
None yet
Development

No branches or pull requests

3 participants