Skip to content

Functions: Effectively/Logically hard coded max python version; exceeding results in silent failure and false pseudo-success #8336

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

Open
paulpv opened this issue Mar 18, 2025 · 2 comments

Comments

@paulpv
Copy link

paulpv commented Mar 18, 2025

I have Python 3.13 installed.

% python3.13 --version
Python 3.13.1

I am trying to follow the guide at https://firebase.google.com/docs/functions/get-started?gen=2nd and run firebase functions with:

firebase init functions
...
firebase emulators:start

The emulator says either...

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.12 -m venv venv'?

... or, if I run cd ./functions && python3 -m venv venv...

Failed to load function definition from source: FirebaseError: Failed to find location of Firebase Functions SDK.
Did you forget to run '. "./functions/venv/bin/activate" && python3.12 -m pip install -r requirements.txt'?

I don't see that logged step documented anywhere.
Apparently you have to run the equivalent of:

pushd functions
python3 -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
deactivate
popd
firebase emulators:start

But that is all moot because it still fails!

Looking at firebase-debug.log: EMPHASIS MINE

...
[info] i  functions: Watching "/Users/pv/Dev/GitHub/swooby/swoo.by/functions" for Cloud Functions... {"metadata":{"emulator":{"name":"functions"},"message":"Watching \"/Users/pv/Dev/GitHub/swooby/swoo.by/functions\" for Cloud Functions..."}}
[debug] [2025-03-18T21:38:02.543Z] Customer code is not Node
[debug] [2025-03-18T21:38:02.543Z] Validating python source
[debug] [2025-03-18T21:38:02.543Z] Building python source
[debug] [2025-03-18T21:38:02.543Z] Could not find functions.yaml. Must use http discovery
*****
[debug] [2025-03-18T21:38:02.545Z] Running command with virtualenv: command=., args=["\"/Users/pv/Dev/GitHub/swooby/swoo.by/functions/venv/bin/activate\"","&&","python3.12","-c","\"import firebase_functions; import os; print(os.path.dirname(firebase_functions.__file__))\""]
[debug] [2025-03-18T21:38:02.553Z] stderr: /bin/sh: python3.12: command not found
*****

[error] ⬢  functions: Failed to load function definition from source: FirebaseError: Failed to find location of Firebase Functions SDK. Did you forget to run '. "/Users/pv/Dev/GitHub/swooby/swoo.by/functions/venv/bin/activate" && python3.12 -m pip install -r requirements.txt'? {"metadata":{"emulator":{"name":"functions"},"message":"Failed to load function definition from source: FirebaseError: Failed to find location of Firebase Functions SDK. Did you forget to run '. \"/Users/pv/Dev/GitHub/swooby/swoo.by/functions/venv/bin/activate\" && python3.12 -m pip install -r requirements.txt'?"}}
[debug] [2025-03-18T21:38:02.555Z] Could not find VSCode notification endpoint: FetchError: request to http://localhost:40001/vscode/notify failed, reason: . If you are not running the Firebase Data Connect VSCode extension, this is expected and not an issue.
...

The root cause is that python3.12 is trying to be used.

Again, I have Python 3.13.

I tried setting firebase.json...

  "functions": [
    {
      "runtime": "python313",
...

...but firebase emulators:start fails with:

% firebase emulators:start
(node:78311) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
i  emulators: Starting emulators: functions, hosting, extensions
⚠  hosting: Port 6000 is restricted by some web browsers, including Chrome. You may want to choose a different port such as 6001.
i  emulators: Shutting down emulators.
i  hub: Stopping emulator hub

Error: Cannot load functions from ./functions because it has invalid runtime python313

Looking at https://github.com/firebase/firebase-tools/blob/master/src/deploy/functions/runtimes/python/index.ts

export function getPythonBinary(
  runtime: supported.Runtime & supported.RuntimeOf<"python">,
): string {
  if (process.platform === "win32") {
    // There is no easy way to get specific version of python executable in Windows.
    return "python.exe";
  }
  if (runtime === "python310") {
    return "python3.10";
  } else if (runtime === "python311") {
    return "python3.11";
  } else if (runtime === "python312") {
    return "python3.12";
  }
  assertExhaustive(runtime, `Unhandled python runtime ${runtime as string}`);
}

This code tells me that Python 3.13 (python313) released 2024-10-07 is not supported?!?!

Where is/are the required/supported python version numbers listed?

Why does specifying an existing valid "runtime": "python313" fail?

Why does defaulting to or specifying a not existing "runtime": "python312" not fail?

This is all a pretty big cluster F.

Wasn't this supposed to be fixed by #6866 ?

[REQUIRED] Environment info

firebase-tools: 13.34.0
Platform: macOS (I do not think this is macOS specific)

[REQUIRED] Test case

?

[REQUIRED] Steps to reproduce

  1. Install Python 3.13 only (do not have any other Python 3 or 2 version installed).
  2. Follow https://firebase.google.com/docs/functions/get-started?gen=2nd
firebase init functions
  1. Init functions to use Python
  2. VERY FRUSTRATINGLY, nothing in the documentation says that it seems like the following additional steps are required?:
pushd functions
python3 -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
deactivate
popd
  1. firebase emulators:start

[REQUIRED] Expected behavior

  • firebase emulator functions work successfully

[REQUIRED] Actual behavior

  • firebase emulator starts [false] successfully
  • debug log says it failed to find python 3.12
  • emulator functions page says
Failed to load function definition from source: FirebaseError: Failed to find location of Firebase Functions SDK. Did you forget to run '. "./functions/venv/bin/activate" && python3.12 -m pip install -r requirements.txt'?

WORKAROUND

Install Python 3.12, but that is a pretty sad/weak workaround.

@paulpv paulpv changed the title Effectively/Logically hard coded max python version; exceeding results in silent failure and false pseudo-success Functions: Effectively/Logically hard coded max python version; exceeding results in silent failure and false pseudo-success Mar 18, 2025
@aalej
Copy link
Contributor

aalej commented Mar 19, 2025

Hey @paulpv, sorry to hear you encountered this issue, and thanks for sharing your observations as well as for creating a detailed report. I'll check this with our engineering team to see what we can do to improve this behavior and to add support for python3.13 runtime.

Regarding step 4, I think this occurred since python313 isn't yet listed in runtime versions. Usually, these steps(creating venv and installing dependencies) are handled by the Firebase CLI during initialization.

edit: At the moment, it doesn't look like the Python 3.13 runtime is supported in Cloud Run Functions https://cloud.google.com/static/functions/docs/concepts/execution-environment#python

@paulpv
Copy link
Author

paulpv commented Mar 22, 2025

Thank you, @aalej .

I still find it odd that:

Why does defaulting to or specifying a not existing "runtime": "python312" not fail?

firebase emulators:start starts running and I would expect it to fail.

Understood about the supported versions lagging a little.

That same link shows Node is supported only up to v22, even though v23 released 2024/10/16.
But that is a major version that is even more understandable to take a little while to support.

Python 3.12->3.13 should be a pretty minor change that is relatively much easier to confirm support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants