Closed sharadregoti closed 1 year ago
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'?
Hi @sharadregoti, thanks for reaching out to us and for providing a detailed description of the issue. I tried to replicate the issue described but I did not encounter any error message when running firebase emulators:start
.
Does running . "/home/sharad/personal/salarygpt/functions/venv/bin/activate" && python3.11 -m pip install -r requirements.txt
in your functions
directory result in any errors? Also, could you try running firebase emulators:start --debug
and share with us the output logs? Passing the --debug
flag provides more details on what could’ve caused the error.
I am using the following to replicate the issue:
@satpalsr, I understand that you’re also experiencing the same issue. Does running python3.11 -m venv venv
in your Python functions
directory result in any errors? Could you also run firebase emulators:start --debug
and share your debug logs, and let us know which Python version you’re using. Thanks!
Ok, When i ran source venv/bin/activate && python3.11 -m pip install -r requirements.txt
I got this error. /usr/bin/python3.11: No module named pip
So, To fix the above issue, I ran the below commands
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3.11 get-pip.py
python3.11 -m pip --version
the last command responded with: pip 23.1.2 from /home/sharad/.local/lib/python3.11/site-packages/pip (python 3.11)
Now when i tried to run the emulator, I got this output (Some connection refused error message on port)
Here is the output with debug log
[2023-05-22T15:29:46.569Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
[2023-05-22T15:29:46.571Z] > authorizing via signed-in user (sharadregoti15@gmail.com)
[2023-05-22T15:29:46.658Z] openjdk version "17.0.7" 2023-04-18
OpenJDK Runtime Environment (build 17.0.7+7-Ubuntu-0ubuntu120.04)
OpenJDK 64-Bit Server VM (build 17.0.7+7-Ubuntu-0ubuntu120.04, mixed mode, sharing)
[2023-05-22T15:29:46.665Z] Parsed Java major version: 17
i emulators: Starting emulators: functions, firestore, storage {"metadata":{"emulator":{"name":"hub"},"message":"Starting emulators: functions, firestore, storage"}}
[2023-05-22T15:29:46.671Z] assigned listening specs for emulators {"user":{"hub":[{"address":"127.0.0.1","family":"IPv4","port":4400}],"ui":[{"address":"127.0.0.1","family":"IPv4","port":4000}],"logging":[{"address":"127.0.0.1","family":"IPv4","port":4500}],"firestore":[{"address":"127.0.0.1","family":"IPv4","port":8080}],"firestore.websocket":[{"address":"127.0.0.1","family":"IPv4","port":9150}],"storage":[{"address":"127.0.0.1","family":"IPv4","port":9199}]},"metadata":{"message":"assigned listening specs for emulators"}}
[2023-05-22T15:29:46.680Z] [hub] writing locator at /tmp/hub-salarygpt-c0c20.json
[2023-05-22T15:29:46.687Z] late-assigned ports for functions and eventarc emulators {"user":{"hub":[{"address":"127.0.0.1","family":"IPv4","port":4400}],"ui":[{"address":"127.0.0.1","family":"IPv4","port":4000}],"logging":[{"address":"127.0.0.1","family":"IPv4","port":4500}],"firestore":[{"address":"127.0.0.1","family":"IPv4","port":8080}],"firestore.websocket":[{"address":"127.0.0.1","family":"IPv4","port":9150}],"storage":[{"address":"127.0.0.1","family":"IPv4","port":9199}],"functions":[{"address":"127.0.0.1","family":"IPv4","port":5001}],"eventarc":[{"address":"127.0.0.1","family":"IPv4","port":9299}]},"metadata":{"message":"late-assigned ports for functions and eventarc emulators"}}
⚠ functions: The following emulators are not running, calls to these services from the Functions emulator will affect production: auth, database, hosting, pubsub {"metadata":{"emulator":{"name":"functions"},"message":"The following emulators are not running, calls to these services from the Functions emulator will affect production: \u001b[1mauth, database, hosting, pubsub\u001b[22m"}}
[2023-05-22T15:29:46.690Z] defaultcredentials: writing to file /home/sharad/.config/firebase/sharadregoti15_gmail_com_application_default_credentials.json
[2023-05-22T15:29:46.691Z] Setting GAC to /home/sharad/.config/firebase/sharadregoti15_gmail_com_application_default_credentials.json {"metadata":{"emulator":{"name":"functions"},"message":"Setting GAC to /home/sharad/.config/firebase/sharadregoti15_gmail_com_application_default_credentials.json"}}
[2023-05-22T15:29:46.693Z] >>> [apiv2][query] GET https://firebase.googleapis.com/v1beta1/projects/salarygpt-c0c20/adminSdkConfig [none]
[2023-05-22T15:29:47.353Z] <<< [apiv2][status] GET https://firebase.googleapis.com/v1beta1/projects/salarygpt-c0c20/adminSdkConfig 200
[2023-05-22T15:29:47.354Z] <<< [apiv2][body] GET https://firebase.googleapis.com/v1beta1/projects/salarygpt-c0c20/adminSdkConfig {"projectId":"salarygpt-c0c20","storageBucket":"salarygpt-c0c20.appspot.com","locationId":"asia-south1"}
[2023-05-22T15:29:47.382Z] Ignoring unsupported arg: auto_download {"metadata":{"emulator":{"name":"firestore"},"message":"Ignoring unsupported arg: auto_download"}}
[2023-05-22T15:29:47.384Z] Ignoring unsupported arg: single_project_mode_error {"metadata":{"emulator":{"name":"firestore"},"message":"Ignoring unsupported arg: single_project_mode_error"}}
[2023-05-22T15:29:47.385Z] Starting Firestore Emulator with command {"binary":"java","args":["-Djava.net.preferIPv4Stack=true","-Dgoogle.cloud_firestore.debug_log_level=FINE","-Duser.language=en","-jar","/home/sharad/.cache/firebase/emulators/cloud-firestore-emulator-v1.17.4.jar","--host","127.0.0.1","--port",8080,"--websocket_port",9150,"--project_id","salarygpt-c0c20","--rules","/home/sharad/personal/salarygpt/firestore.rules","--single_project_mode",true,"--functions_emulator","127.0.0.1:5001"],"optionalArgs":["port","webchannel_port","host","rules","websocket_port","functions_emulator","seed_from_export","project_id","single_project_mode"],"joinArgs":false} {"metadata":{"emulator":{"name":"firestore"},"message":"Starting Firestore Emulator with command {\"binary\":\"java\",\"args\":[\"-Djava.net.preferIPv4Stack=true\",\"-Dgoogle.cloud_firestore.debug_log_level=FINE\",\"-Duser.language=en\",\"-jar\",\"/home/sharad/.cache/firebase/emulators/cloud-firestore-emulator-v1.17.4.jar\",\"--host\",\"127.0.0.1\",\"--port\",8080,\"--websocket_port\",9150,\"--project_id\",\"salarygpt-c0c20\",\"--rules\",\"/home/sharad/personal/salarygpt/firestore.rules\",\"--single_project_mode\",true,\"--functions_emulator\",\"127.0.0.1:5001\"],\"optionalArgs\":[\"port\",\"webchannel_port\",\"host\",\"rules\",\"websocket_port\",\"functions_emulator\",\"seed_from_export\",\"project_id\",\"single_project_mode\"],\"joinArgs\":false}"}}
i firestore: Firestore Emulator logging to firestore-debug.log {"metadata":{"emulator":{"name":"firestore"},"message":"Firestore Emulator logging to \u001b[1mfirestore-debug.log\u001b[22m"}}
[2023-05-22T15:29:48.236Z] May 22, 2023 8:59:48 PM com.google.cloud.datastore.emulator.firestore.websocket.WebSocketServer start
INFO: Started WebSocket server on ws://127.0.0.1:9150
{"metadata":{"emulator":{"name":"firestore"},"message":"May 22, 2023 8:59:48 PM com.google.cloud.datastore.emulator.firestore.websocket.WebSocketServer start\nINFO: Started WebSocket server on ws://127.0.0.1:9150\n"}}
[2023-05-22T15:29:48.252Z] API endpoint: http://127.0.0.1:8080
{"metadata":{"emulator":{"name":"firestore"},"message":"API endpoint: http://127.0.0.1:8080\n"}}
[2023-05-22T15:29:48.252Z] If you are using a library that supports the FIRESTORE_EMULATOR_HOST environment variable, run:
export FIRESTORE_EMULATOR_HOST=127.0.0.1:8080
Dev App Server is now running.
{"metadata":{"emulator":{"name":"firestore"},"message":"If you are using a library that supports the FIRESTORE_EMULATOR_HOST environment variable, run:\n\n export FIRESTORE_EMULATOR_HOST=127.0.0.1:8080\n\nDev App Server is now running.\n\n"}}
✔ firestore: Firestore Emulator UI websocket is running on 9150. {"metadata":{"emulator":{"name":"firestore"},"message":"Firestore Emulator UI websocket is running on 9150."}}
[2023-05-22T15:29:48.406Z] Ignoring unsupported arg: port {"metadata":{"emulator":{"name":"storage"},"message":"Ignoring unsupported arg: port"}}
[2023-05-22T15:29:49.111Z] Temp file directory for storage emulator: /tmp/firebase/storage/blobs {"metadata":{"emulator":{"name":"storage"},"message":"Temp file directory for storage emulator: /tmp/firebase/storage/blobs"}}
[2023-05-22T15:29:49.121Z] Ignoring unsupported arg: auto_download {"metadata":{"emulator":{"name":"ui"},"message":"Ignoring unsupported arg: auto_download"}}
[2023-05-22T15:29:49.121Z] Ignoring unsupported arg: port {"metadata":{"emulator":{"name":"ui"},"message":"Ignoring unsupported arg: port"}}
[2023-05-22T15:29:49.121Z] Starting Emulator UI with command {"binary":"node","args":["/home/sharad/.cache/firebase/emulators/ui-v1.11.6/server/server.js"],"optionalArgs":[],"joinArgs":false} {"metadata":{"emulator":{"name":"ui"},"message":"Starting Emulator UI with command {\"binary\":\"node\",\"args\":[\"/home/sharad/.cache/firebase/emulators/ui-v1.11.6/server/server.js\"],\"optionalArgs\":[],\"joinArgs\":false}"}}
i ui: Emulator UI logging to ui-debug.log {"metadata":{"emulator":{"name":"ui"},"message":"Emulator UI logging to \u001b[1mui-debug.log\u001b[22m"}}
[2023-05-22T15:29:49.217Z] Web / API server started at 127.0.0.1:4000
{"metadata":{"emulator":{"name":"ui"},"message":"Web / API server started at 127.0.0.1:4000\n"}}
i functions: Watching "/home/sharad/personal/salarygpt/functions" for Cloud Functions... {"metadata":{"emulator":{"name":"functions"},"message":"Watching \"/home/sharad/personal/salarygpt/functions\" for Cloud Functions..."}}
[2023-05-22T15:29:49.385Z] Customer code is not Node
[2023-05-22T15:29:49.385Z] Validating python source
[2023-05-22T15:29:49.386Z] Building python source
[2023-05-22T15:29:49.387Z] Could not find functions.yaml. Must use http discovery
[2023-05-22T15:29:49.388Z] Running command with virtualenv: command=., args=["\"/home/sharad/personal/salarygpt/functions/venv/bin/activate\"","&&","python3.11","-c","\"import firebase_functions; import os; print(os.path.dirname(firebase_functions.__file__))\""]
[2023-05-22T15:29:49.413Z] stdout: /home/sharad/.local/lib/python3.11/site-packages/firebase_functions
[2023-05-22T15:29:49.416Z] Running admin server with args: ["python3.11","\"/home/sharad/.local/lib/python3.11/site-packages/firebase_functions/private/serving.py\""] and env: {"GCLOUD_PROJECT":"salarygpt-c0c20","K_REVISION":"1","PORT":"80","FUNCTIONS_EMULATOR":"true","TZ":"UTC","FIREBASE_DEBUG_MODE":"true","FIREBASE_DEBUG_FEATURES":"{\"skipTokenVerification\":true,\"enableCors\":true}","FIREBASE_EMULATOR_HUB":"127.0.0.1:4400","FIRESTORE_EMULATOR_HOST":"127.0.0.1:8080","FIREBASE_FIRESTORE_EMULATOR_ADDRESS":"127.0.0.1:8080","FIREBASE_STORAGE_EMULATOR_HOST":"127.0.0.1:9199","STORAGE_EMULATOR_HOST":"http://127.0.0.1:9199","CLOUD_EVENTARC_EMULATOR_HOST":"http://127.0.0.1:9299","FIREBASE_CONFIG":"{\"storageBucket\":\"salarygpt-c0c20.appspot.com\",\"projectId\":\"salarygpt-c0c20\"}","GOOGLE_APPLICATION_CREDENTIALS":"/home/sharad/.config/firebase/sharadregoti15_gmail_com_application_default_credentials.json","ADMIN_PORT":"8081"} in /home/sharad/personal/salarygpt/functions
[2023-05-22T15:29:49.416Z] Running command with virtualenv: command=., args=["\"/home/sharad/personal/salarygpt/functions/venv/bin/activate\"","&&","python3.11","\"/home/sharad/.local/lib/python3.11/site-packages/firebase_functions/private/serving.py\""]
[2023-05-22T15:29:49.843Z] stderr: Traceback (most recent call last):
File "/home/sharad/.local/lib/python3.11/site-packages/firebase_functions/private/serving.py", line 29, in <module>
from firebase_functions.private import manifest as _manifest
File "/home/sharad/.local/lib/python3.11/site-packages/firebase_functions/private/manifest.py", line 25, in <module>
import firebase_functions.private.util as _util
File "/home/sharad/.local/lib/python3.11/site-packages/firebase_functions/private/util.py", line 25, in <module>
from firebase_admin import auth as _auth
File "/home/sharad/.local/lib/python3.11/site-packages/firebase_admin/__init__.py", line 21, in <module>
from firebase_admin import credentials
File "/home/sharad/.local/lib/python3.11/site-packages/firebase_admin/credentials.py", line 21, in <module>
[2023-05-22T15:29:49.843Z] stderr: from google.auth.transport import requests
File "/home/sharad/.local/lib/python3.11/site-packages/google/auth/transport/requests.py", line 26, in <module>
import requests
File "/usr/lib/python3/dist-packages/requests/__init__.py", line 95, in <module>
from urllib3.contrib import pyopenssl
File "/usr/lib/python3/dist-packages/urllib3/contrib/pyopenssl.py", line 46, in <module>
import OpenSSL.SSL
File "/usr/lib/python3/dist-packages/OpenSSL/__init__.py", line 8, in <module>
from OpenSSL import crypto, SSL
File "/usr/lib/python3/dist-packages/OpenSSL/crypto.py", line 1553, in <module>
class X509StoreFlags(object):
File "/usr/lib/python3/dist-packages/OpenSSL/crypto.py", line 1573, in X509StoreFlags
CB_ISSUER_CHECK = _lib.X509_V_FLAG_CB_ISSUER_CHECK
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK'
⚠ functions: Failed to detect functions from source FirebaseError: User code failed to load. Cannot determine backend specification.
stderr:Traceback (most recent call last):
File "/home/sharad/.local/lib/python3.11/site-packages/firebase_functions/private/serving.py", line 29, in <module>
from firebase_functions.private import manifest as _manifest
File "/home/sharad/.local/lib/python3.11/site-packages/firebase_functions/private/manifest.py", line 25, in <module>
import firebase_functions.private.util as _util
File "/home/sharad/.local/lib/python3.11/site-packages/firebase_functions/private/util.py", line 25, in <module>
from firebase_admin import auth as _auth
File "/home/sharad/.local/lib/python3.11/site-packages/firebase_admin/__init__.py", line 21, in <module>
from firebase_admin import credentials
File "/home/sharad/.local/lib/python3.11/site-packages/firebase_admin/credentials.py", line 21, in <module>
from google.auth.transport import requests
File "/home/sharad/.local/lib/python3.11/site-packages/google/auth/transport/requests.py", line 26, in <module>
import requests
File "/usr/lib/python3/dist-packages/requests/__init__.py", line 95, in <module>
from urllib3.contrib import pyopenssl
File "/usr/lib/python3/dist-packages/urllib3/contrib/pyopenssl.py", line 46, in <module>
import OpenSSL.SSL
File "/usr/lib/python3/dist-packages/OpenSSL/__init__.py", line 8, in <module>
from OpenSSL import crypto, SSL
File "/usr/lib/python3/dist-packages/OpenSSL/crypto.py", line 1553, in <module>
class X509StoreFlags(object):
File "/usr/lib/python3/dist-packages/OpenSSL/crypto.py", line 1573, in X509StoreFlags
CB_ISSUER_CHECK = _lib.X509_V_FLAG_CB_ISSUER_CHECK
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK'
⬢ functions: Failed to load function definition from source: FetchError: request to http://127.0.0.1:8081/__/quitquitquit failed, reason: connect ECONNREFUSED 127.0.0.1:8081 {"metadata":{"emulator":{"name":"functions"},"message":"Failed to load function definition from source: FetchError: request to http://127.0.0.1:8081/__/quitquitquit failed, reason: connect ECONNREFUSED 127.0.0.1:8081"}}
i functions: Watching "/home/sharad/personal/salarygpt/js-functions" for Cloud Functions... {"metadata":{"emulator":{"name":"functions"},"message":"Watching \"/home/sharad/personal/salarygpt/js-functions\" for Cloud Functions..."}}
[2023-05-22T15:29:59.576Z] Validating nodejs source
[2023-05-22T15:29:59.947Z] > [functions] package.json contents: {
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"lint": "eslint .",
"serve": "firebase emulators:start --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "18"
},
"main": "index.js",
"dependencies": {
"firebase-admin": "^11.8.0",
"firebase-functions": "^4.3.1"
},
"devDependencies": {
"eslint": "^8.15.0",
"eslint-config-google": "^0.14.0",
"firebase-functions-test": "^3.1.0"
},
"private": true
}
[2023-05-22T15:29:59.948Z] Building nodejs source
[2023-05-22T15:29:59.948Z] Failed to find version of module node: reached end of search path /home/sharad/personal/salarygpt/js-functions/node_modules
⚠ functions: Your requested "node" version "18" doesn't match your global version "16". Using node@16 from host.
[2023-05-22T15:29:59.950Z] Could not find functions.yaml. Must use http discovery
[2023-05-22T15:29:59.951Z] Found firebase-functions binary at '/home/sharad/personal/salarygpt/js-functions/node_modules/.bin/firebase-functions'
[2023-05-22T15:30:00.082Z] Serving at port 8470
[2023-05-22T15:30:00.230Z] Got response from /__/functions.yaml {"endpoints":{"addmessage":{"availableMemoryMb":null,"timeoutSeconds":null,"minInstances":null,"maxInstances":null,"ingressSettings":null,"concurrency":null,"serviceAccountEmail":null,"vpc":null,"platform":"gcfv2","labels":{},"httpsTrigger":{},"entryPoint":"addmessage"},"makeuppercase":{"availableMemoryMb":null,"timeoutSeconds":null,"minInstances":null,"maxInstances":null,"ingressSettings":null,"concurrency":null,"serviceAccountEmail":null,"vpc":null,"platform":"gcfv2","labels":{},"eventTrigger":{"eventType":"google.cloud.firestore.document.v1.created","eventFilters":{"database":"(default)","namespace":"(default)"},"eventFilterPathPatterns":{"document":"messages/{documentId}"},"retry":false},"entryPoint":"makeuppercase"}},"specVersion":"v1alpha1","requiredAPIs":[]}
[2023-05-22T15:30:00.237Z] shutdown requested via /__/quitquitquit
✔ functions: Loaded functions definitions from source: addmessage, makeuppercase. {"metadata":{"emulator":{"name":"functions"},"message":"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). {"metadata":{"emulator":{"name":"functions"},"message":"\u001b[1mhttp\u001b[22m function initialized (http://127.0.0.1:5001/salarygpt-c0c20/us-central1/addmessage)."}}
[2023-05-22T15:30:00.244Z] Found a v2 firestore trigger.
[2023-05-22T15:30:00.244Z] addFirestoreTrigger "{\"eventType\":\"google.cloud.firestore.document.v1.created\",\"database\":\"(default)\",\"namespace\":\"(default)\",\"document\":{\"value\":\"messages/{documentId}\",\"matchType\":\"PATH_PATTERN\"}}"
[2023-05-22T15:30:00.244Z] >>> [apiv2][query] POST http://127.0.0.1:8080/emulator/v1/projects/salarygpt-c0c20/eventarcTrigger?eventarcTriggerId=us-central1-makeuppercase-0 [none]
[2023-05-22T15:30:00.244Z] >>> [apiv2][body] POST http://127.0.0.1:8080/emulator/v1/projects/salarygpt-c0c20/eventarcTrigger?eventarcTriggerId=us-central1-makeuppercase-0 "{\"eventType\":\"google.cloud.firestore.document.v1.created\",\"database\":\"(default)\",\"namespace\":\"(default)\",\"document\":{\"value\":\"messages/{documentId}\",\"matchType\":\"PATH_PATTERN\"}}"
[2023-05-22T15:30:00.249Z] May 22, 2023 9:00:00 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected non-HTTP/2 connection.
{"metadata":{"emulator":{"name":"firestore"},"message":"May 22, 2023 9:00:00 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead\nINFO: Detected non-HTTP/2 connection.\n"}}
[2023-05-22T15:30:00.399Z] May 22, 2023 9:00:00 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected HTTP/2 connection.
{"metadata":{"emulator":{"name":"firestore"},"message":"May 22, 2023 9:00:00 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead\nINFO: Detected HTTP/2 connection.\n"}}
[2023-05-22T15:30:02.835Z] <<< [apiv2][status] POST http://127.0.0.1:8080/emulator/v1/projects/salarygpt-c0c20/eventarcTrigger?eventarcTriggerId=us-central1-makeuppercase-0 200
[2023-05-22T15:30:02.836Z] <<< [apiv2][body] POST http://127.0.0.1:8080/emulator/v1/projects/salarygpt-c0c20/eventarcTrigger?eventarcTriggerId=us-central1-makeuppercase-0 {"eventType":"google.cloud.firestore.document.v1.created","database":"(default)","namespace":"(default)","document":{"value":"messages/{documentId}","matchType":"PATH_PATTERN"}}
✔ functions[us-central1-makeuppercase]: firestore function initialized. {"metadata":{"emulator":{"name":"functions"},"message":"\u001b[1mfirestore\u001b[22m 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 actually had functions folder which contained main.py When I created venv inside functions folder. It worked.
Hi, The above error that i mentioned. Is a python error of my environment.
python3.11 -m pip install pyopenssl --upgrade
python3.11 -m pip install testresources
python3.11 -m pip install --upgrade setuptools
Closing this issue, As it works for me now.
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'?
+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.
I just created some functions with Python: functions % ls -ll total 16 -rw-r--r-- 1 user staff 398 Jun 25 11:24 main.py -rw-r--r-- 1 user staff 25 Jun 25 11:11 requirements.txt drwxr-xr-x 6 user staff 192 Jun 25 11:20 venv
I've already created venv dir as told here before, but I still can't deploy my python fuction:
firebase deploy --only functions
=== Deploying to 'hellofirebase-1b3e6'...
i deploying functions i functions: preparing codebase default for deployment i functions: ensuring required API cloudfunctions.googleapis.com is enabled... i functions: ensuring required API cloudbuild.googleapis.com is enabled... i artifactregistry: ensuring required API artifactregistry.googleapis.com is enabled... ✔ artifactregistry: required API artifactregistry.googleapis.com is enabled ✔ functions: required API cloudfunctions.googleapis.com is enabled ✔ functions: required API cloudbuild.googleapis.com is enabled
Error: Failed to find location of Firebase Functions SDK. Did you forget to run '. "/Users/users/git/live/demos/firebase/hello-python-functions/functions/venv/bin/activate" && python3.11 -m pip install -r requirements.txt'?
Having trouble? Try firebase [command] --help
Same issue
I started by creating a new directory and running firebase init
.
After that, I made changes to the "main.py" and "requirements.txt" files in the new project.
Next, I activated the virtual environment (venv) and installed the package using pip3 install -r requirements.txt
.
Finally, I deployed the project using the command firebase deploy
and that resolved the issue.
I would be happy if my answer was helpful to all of you.
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.
Thanks, @hmalik144 , that mostly worked. I had to switch from python=3.10 to python=3.11 to get past this error.
I had to merge both @Masumi-M and @hmalik144 to work. I created a fire directory and once I ran firebase init
and chose python(also install all depencies) it created the venv folder. I did ran source functions/venv/bin/activate && python -m pip install -r functions/requirements.txt
and all went well.
FYI, I updated the functions
config in my firebase.json
so that every time I deploy my functions, the build (pip install) steps are run using the pip binary packaged with venv. You can do the same by adding the below functions config into your own firebaase.json (note that this is expecting your function source code to be nested under ./src/functions/python-funcs
"functions": [{
"codebase": "python-funcs",
"predeploy": ["(cd ./src/functions/python-funcs; python3.11 -m venv venv; ./venv/bin/pip install -r requirements.txt)"],
"source": "./src/functions/python-funcs"
}],
Now every time you run firebase deploy --only functions:python-funcs
, the virtualenv will be created and packages installed
The fix to me was:
brew install python@3.11
)python3.11 -m venv venv
"predeploy": [
"source functions/venv/bin/activate && python3.11 -m pip install -r functions/requirements.txt"
],
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!
I actually had functions folder which contained main.py When I created venv inside functions folder. It worked.
That fixed the error on my side. Creating the venv
side by side where themain.py
is solved the issue.
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.
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
Upgrading to python 3.12 and creating the venv using it fixed it for me. This issue really needs reopening and fixing.
Here's what I found, and a fix (I think).
By default, it will try to use the latest runtime that's supported, so looks for python3.12
in your venv. If you only have 3.11 installed, then it'll fail.
The idea is that it should be analyzing your code with the same version of Python that it's going to deploy with. By default, it will deploy to the latest runtime available, so that's what it tries to run when it's analyzing your functions.
I promised you a fix. Add an explicit runtime
to your firebase.json
:
"functions": [
{
"runtime": "python311", // This is the line you add (and not this comment)
"source": "functions",
"codebase": "default",
This is extraordinarily painful. I downloaded 3.12, still didn't work.
takaomatt@Matts-MacBook-Air signal % python3 --version
Python 3.12.7
takaomatt@Matts-MacBook-Air functions % . venv/bin/activate
(venv) takaomatt@Matts-MacBook-Air functions % python3 -m pip install -r requirements.txt
Requirement already satisfied
...
Adding "runtime": "python312"
to firebase.json:
Error: Cannot deploy function with runtime python312
Downloaded 3.11, ran the venv, activate, install, and then it got past that error onto this lovely one:
=== Deploying to 'signal-fda08'...
i deploying functions
i functions: preparing codebase default for deployment
i functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i functions: ensuring required API cloudbuild.googleapis.com is enabled...
i artifactregistry: ensuring required API artifactregistry.googleapis.com is enabled...
✔ functions: required API cloudbuild.googleapis.com is enabled
✔ artifactregistry: required API artifactregistry.googleapis.com is enabled
✔ functions: required API cloudfunctions.googleapis.com is enabled
i functions: Loading and analyzing source code for codebase default to determine what to deploy
/Users/takaomatt/flutter-repos/signal/functions/venv/lib/python3.11/site-packages/requests/__init__.py:86: RequestsDependencyWarning: Unable to find acceptable character detection dependency (chardet or charset_normalizer).
warnings.warn(
Traceback (most recent call last):
File "/Users/takaomatt/flutter-repos/signal/functions/venv/lib/python3.11/site-packages/firebase_functions/private/serving.py", line 30, in <module>
from firebase_functions.private import manifest as _manifest
File "/Users/takaomatt/flutter-repos/signal/functions/venv/lib/python3.11/site-packages/firebase_functions/private/manifest.py", line 25, in <module>
import firebase_functions.private.util as _util
File "/Users/takaomatt/flutter-repos/signal/functions/venv/lib/python3.11/site-packages/firebase_functions/private/util.py", line 27, in <module>
from firebase_admin import app_check as _app_check
File "/Users/takaomatt/flutter-repos/signal/functions/venv/lib/python3.11/site-packages/firebase_admin/app_check.py", line 18, in <module>
import jwt
File "/Users/takaomatt/flutter-repos/signal/functions/venv/lib/python3.11/site-packages/jwt/__init__.py", line 1, in <module>
from .api_jwk import PyJWK, PyJWKSet
File "/Users/takaomatt/flutter-repos/signal/functions/venv/lib/python3.11/site-packages/jwt/api_jwk.py", line 7, in <module>
from .algorithms import get_default_algorithms, has_crypto, requires_cryptography
File "/Users/takaomatt/flutter-repos/signal/functions/venv/lib/python3.11/site-packages/jwt/algorithms.py", line 11, in <module>
from .utils import (
File "/Users/takaomatt/flutter-repos/signal/functions/venv/lib/python3.11/site-packages/jwt/utils.py", line 7, in <module>
from cryptography.hazmat.primitives.asymmetric.ec import EllipticCurve
File "/Users/takaomatt/flutter-repos/signal/functions/venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/ec.py", line 11, in <module>
from cryptography.exceptions import UnsupportedAlgorithm, _Reasons
File "/Users/takaomatt/flutter-repos/signal/functions/venv/lib/python3.11/site-packages/cryptography/exceptions.py", line 9, in <module>
from cryptography.hazmat.bindings._rust import exceptions as rust_exceptions
ImportError: dlopen(/Users/takaomatt/flutter-repos/signal/functions/venv/lib/python3.11/site-packages/_cffi_backend.cpython-311-darwin.so, 0x0002): tried: '/Users/takaomatt/flutter-repos/signal/functions/venv/lib/python3.11/site-packages/_cffi_backend.cpython-311-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/takaomatt/flutter-repos/signal/functions/venv/lib/python3.11/site-packages/_cffi_backend.cpython-311-darwin.so' (no such file), '/Users/takaomatt/flutter-repos/signal/functions/venv/lib/python3.11/site-packages/_cffi_backend.cpython-311-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))
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
[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
Error