firebase-tools: FirebaseError: Failed to find location of Firebase Functions SDK.

When trying to start the Cloud Functions emulator that uses Python, an error is being raised.

[REQUIRED] Environment info

firebase-tools: firebase-tools: 12.1.0

Platform: Platform: linux (windows wsl2)

Node: v16.17.0

Python: v3.11.3

[REQUIRED] Test case

[REQUIRED] Steps to reproduce

  1. Follow this getting started guide of firebase function for python https://firebase.google.com/docs/functions/get-started?gen=2nd#about_this_tutorial

[REQUIRED] Expected behavior

No error should have occured & I should have gotten a URL for testing function

[REQUIRED] Actual behavior

Whenever i run firebase emulators:start

i emulators: Starting emulators: functions, firestore, storage ⚠ functions: The following emulators are not running, calls to these services from the Functions emulator will affect production: auth, database, hosting, pubsub i firestore: Firestore Emulator logging to firestore-debug.log ✔ firestore: Firestore Emulator UI websocket is running on 9150. i ui: Emulator UI logging to ui-debug.log i functions: Watching “/home/sharad/personal/salarygpt/functions” for Cloud Functions… ⬢ functions: Failed to load function definition from source: FirebaseError: Failed to find location of Firebase Functions SDK. Did you forget to run ‘. “/home/sharad/personal/salarygpt/functions/venv/bin/activate” && python3.11 -m pip install -r requirements.txt’? i functions: Watching “/home/sharad/personal/salarygpt/js-functions” for Cloud Functions… ⚠ functions: Your requested “node” version “18” doesn’t match your global version “16”. Using node@16 from host. ✔ functions: Loaded functions definitions from source: addmessage, makeuppercase. ✔ functions[us-central1-addmessage]: http function initialized (http://127.0.0.1:5001/salarygpt-c0c20/us-central1/addmessage). ✔ functions[us-central1-makeuppercase]: firestore function initialized.

┌─────────────────────────────────────────────────────────────┐ │ ✔ All emulators ready! It is now safe to connect your app. │ │ i View Emulator UI at http://127.0.0.1:4000/ │ └─────────────────────────────────────────────────────────────┘

┌───────────┬────────────────┬─────────────────────────────────┐ │ Emulator │ Host:Port │ View in Emulator UI │ ├───────────┼────────────────┼─────────────────────────────────┤ │ Functions │ 127.0.0.1:5001 │ http://127.0.0.1:4000/functions │ ├───────────┼────────────────┼─────────────────────────────────┤ │ Firestore │ 127.0.0.1:8080 │ http://127.0.0.1:4000/firestore │ ├───────────┼────────────────┼─────────────────────────────────┤ │ Storage │ 127.0.0.1:9199 │ http://127.0.0.1:4000/storage │ └───────────┴────────────────┴─────────────────────────────────┘ Emulator Hub running at 127.0.0.1:4400 Other reserved ports: 4500, 9150

Issues? Report them at https://github.com/firebase/firebase-tools/issues and attach the *-debug.log files.

I am using both JS & python functions.

This is my project structure image

Error image

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 19 (1 by maintainers)

Most upvoted comments

Exactly same problem I am facing. I am just using python and following the same guide. If no venv is created, I get the message you shared. Failed to load function definition from source: FirebaseError: Failed to find location of Firebase Functions SDK. Did you forget to run '. "/home/myproject/functions/venv/bin/activate" && python3.11 -m pip install -r requirements.txt'?

When I create venv I get Failed to load function definition from source: FirebaseError: Failed to find location of Firebase Functions SDK: Missing virtual environment at venv directory. Did you forget to run 'python3.11 -m venv venv'?

Running these commands before starting the emulator got rid of the error:

python -m venv functions/venv
source functions/venv/bin/activate && python -m pip install -r functions/requirements.txt

Its probably worth mentioning I am running this in circleci.

I actually had functions folder which contained main.py When I created venv inside functions folder. It worked.

What fixed the problem for me was upgrading Python from version 3.11 to 3.12.

I’m not entirely sure how firebase functions work, but I think when you initialize it on your local machine with python, it automatically chooses perhaps the latest stable release of python and if your local python version is behind it (like mine was), you’ll get problems.

This fixed the issue for me as well, even though firebase docs say that functions only work with Python 3.11

Having the same issue if I don’t have the venv when deploying, the deployment fails. What is the hard dependency on the venv and why is this mandatory? This affects CI/CD pipelines and requires the user to download the dependencies and use venv to deploy and emulate the function.

firebase emulators:start --only functions --debug

[2023-06-21T19:57:21.116Z] stderr: /bin/sh: /Users/dkjfhdkjf/Documents/Github/dgdfkghkdfjg/functions/venv/bin/activate: No such file or directory

⬢  functions: Failed to load function definition from source: FirebaseError: Failed to find location of Firebase Functions SDK: Missing virtual environment at venv directory. Did you forget to run 'python3.11 -m venv venv'? {"metadata":{"emulator":{"name":"functions"},"message":"Failed to load function definition from source: FirebaseError: Failed to find location of Firebase Functions SDK: Missing virtual environment at venv directory. Did you forget to run 'python3.11 -m venv venv'?"}}

firebase deploy --only functions --debug

[2023-06-21T19:48:45.492Z] Customer code is not Node
[2023-06-21T19:48:45.492Z] Validating python source
[2023-06-21T19:48:45.493Z] Building python source
[2023-06-21T19:48:45.493Z] Could not find functions.yaml. Must use http discovery
[2023-06-21T19:48:45.502Z] Running command with virtualenv: command=., args=["\"/Users/fghfghfghfgh/Documents/Github/fghfghfghfgh/functions/venv/bin/activate\"","&&","python3.11","-c","\"import firebase_functions; import os; print(os.path.dirname(firebase_functions.__file__))\""]
[2023-06-21T19:48:45.515Z] stderr: /bin/sh: /Users/fghfghfgh/Documents/Github/fghfghfghfghf/functions/venv/bin/activate: No such file or directory


Error: Failed to find location of Firebase Functions SDK: Missing virtual environment at venv directory. Did you forget to run 'python3.11 -m venv venv'?

What fixed the problem for me was upgrading Python from version 3.11 to 3.12.

I’m not entirely sure how firebase functions work, but I think when you initialize it on your local machine with python, it automatically chooses perhaps the latest stable release of python and if your local python version is behind it (like mine was), you’ll get problems.

+1, the dependence upon virtualenv means I now need to carry around all my dependencies and check them into my VCS. IMO the build pack should just look for a requirements.txt in the functions directory and use that to install packages at build time (just like normal Cloud Functions). It should then be up to the user to pin their packages to ensure nothing breaks.

My problem was, I was creating the virtualenv with python3.10.

When I typed virtualenv venv it used python3.10 to create it. I did python3 --version and it showed v3.11, so I created it this way: python3 -m venv venv instead, then source venv/bin/activate, then pip install -r requirements.txt et voila!