firebase-tools
firebase-tools copied to clipboard
Functions Python version conflict 3.12 and 3.11
[REQUIRED] Environment info
firebase-tools: 13.3.0
Platform: macOS, Ubuntu (Github Actions)
[REQUIRED] Test case
Fresh Python functions project with both Python 3.11 and 3.12 installed
[REQUIRED] Steps to reproduce
- Start a new (or use existing) Firebase project and init Python functions
- Install Python 3.12
- Build the venv
- Install pip requirements (firebase-functions, firebase-admin)
- Build a function
- Attempt to run the emulators and it complains that you're not using Python 3.11
Failed to load function definition from source: FirebaseError: Failed to find location of Firebase Functions SDK. Did you forget to run '. "<redacted>/venv/bin/activate" && python3.11 -m pip install -r requirements.txt'?
- Install Python 3.11
- Build the venv using 3.11
- Install pip requirements using 3.11
- Emulators run
- Attempt to deploy the functions and it complains that you're not using Python 3.12
Error: Failed to find location of Firebase Functions SDK. Did you forget to run '. "<redacted>/venv/bin/activate" && python3.12 -m pip install -r requirements.txt'?
[REQUIRED] Expected behavior
Emulators should work with Python 3.12 and deploy should work with Python 3.11 when both are installed.
[REQUIRED] Actual behavior
Emulators fail to start the Python functions if the venv was setup using 3.12 Deploy fails when venv was setup using 3.11 if 3.12 is also installed
I've got the same issue: since firebase-tools switched to version 13.3.0, my Github Actions builds fail to deploy Python Cloud functions (I am using python3.11, and with [email protected] it was working fine).
Run npx firebase-tools deploy --only functions --force --json --project *** --token ***
npm WARN exec The following package was not found and will be installed: [email protected]
***
"status": "error",
"error": "Failed to find location of Firebase Functions SDK. Did you forget to run '. \"/home/runner/work/webapp/webapp/functions-python/venv/bin/activate\" && python3.12 -m pip install -r requirements.txt'?"
***
PS Of course the fix is to simply to pre-install the working version, so this is just to report the bug on the new version.
@antopolskiy So far our fix has been to pin firebase-tools to 13.2.1 for now.
I got the same error and found a fix.
This error occurred when the runtime configuration was omitted from firebase.json. If your runtime is using python 3.11, it should look like this:
{
"functions": [
{
"source": "functions",
"codebase": "default",
"runtime": "python311", <--- here
}
],
}
If the config is omitted, firebase-tools attempt to find latest python version.
https://github.com/firebase/firebase-tools/blob/09c2641e861f2e31798dfb4aba1a180e8fd08ea5/src/deploy/functions/runtimes/python/index.ts#L33
But I think it makes more sense to use the default python binary than to find the latest version when the configuration is missing, which is already done by getPythonBinary.
https://github.com/firebase/firebase-tools/blob/09c2641e861f2e31798dfb4aba1a180e8fd08ea5/src/deploy/functions/runtimes/python/index.ts#L50-L57
I think I'll make PR for it
After further reading, it seems more reasonable to throw an error when the runtime field is missing, since the node.js function is already doing so.
Hey folks, thanks for reporting this issue, and thanks @kmsbernard, for sharing your observations. I’m unable to reproduce the issue when using python3.12, however I was able to reproduce this using python3.11.
Let me know in case I made a mistake in following the provided steps. From what I can tell, the steps are:
- Run
firebase init functions --project <project_id>- Choose Python
- Do you want to install dependencies now? No
- Run
cd functions - Run
python3.11 -m venv venv - Run
. venv/bin/activate && python3.11 -m pip install -r requirements.txt - Uncomment the example function in
main.py - Run
firebase emulators:start- Emulators raise an issue
It does seem like the issue here is that firebase-tools tries to find the latest version of python(currently 3.12). Setting the runtime as mentioned in https://github.com/firebase/firebase-tools/issues/6774#issuecomment-1953399977 fixes the issue.
Let me raise this issue to our engineering team so that we can determine the appropriate action for this. Also, feel free to make a PR for this if you’re up for it! Contributions are always welcome.
@kmsbernard That's awesome, thanks! We're going to set this and see how it behaves.
@aalej Thanks for looking into this, my steps to reproduce might have been a bit off as we're mainly getting this issue on a Github Actions runner that has at least 6 different Python versions vs a local environment that we have more control over. Some is local in the case of the emulators, some is the runner in the case of the error using Python 3.12 instead of 3.11.
It all stems from not having the runtime option configured in firebase.json. I think maybe another question is "Should firebase init functions be initializing the runtime option?" In my "ignorant Firebase noob" world, the answer to that question is "Yes, it should initialize to the latest version the platform supports." As it stands right now, I didn't even realize it wasn't set and firebase-tools was trying to reason about it. If it were set by default (or even erroring if not specified), the necessity of reasoning about it is basically eliminated and it becomes the responsibility of the user to make sure it's set correctly.
Hello. I can reproduce this issue with Python 3.11 as well. Adding a runtime does fix it, however my LSP does warn me of a unknown value. I'm guessing the schema for firebase.json is not updated.
LSP warning in JSON:
Value is not accepted. Valid values: "nodejs10", "nodejs12", "nodejs14", "nodejs16", "nodejs18", "nodejs20".