ModuleNotFoundError Google Cloud / Firebase Origin: Platform & cloud OSI layer 7 · Application Last updated 18 Nov 2026

Cloud Functions Python: ModuleNotFoundError: No module named 'X' (requirements.txt)

The deployed Python function imports a package that wasn't installed from requirements.txt.

Exact message you may see ModuleNotFoundError: No module named in Cloud FunctionsFunction failed on loading user code ModuleNotFoundErrorCloud Functions Python requirements.txt missingImportError: cannot import name Cloud FunctionCould not load the function
Seen on: Google Cloud Python

Meaning

List every third-party import in requirements.txt with versions, keep main.py and requirements.txt at the function's root, and watch for packages needing system libraries. Check the build logs for pip errors.

Common causes

  • Package missing from requirements.txt
  • requirements.txt not at the source root
  • Version conflict during pip install
  • Needs a system library not in the runtime
  • Wrong entry-point module name

⚡ Quick fix

  1. Add the package to requirements.txt
  2. Place main.py and requirements.txt in the deploy root
  3. Pin compatible versions

Detailed fix by platform

Shell

  1. bash
    printf "functions-framework==3.*
    requests==2.32.3
    " > requirements.txt
    gcloud functions deploy fn --gen2 --runtime=python312 --trigger-http --entry-point=handler

How to diagnose

  1. requirements.txt — Complete?
  2. Location — Source root?
  3. Build log — pip errors?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Platform & cloud. Errors that are often confused with or caused by this one (click to open):

App Engine — App Engine deploy failed: invalid app.yaml (runtime not supported / entrypoint / handlers) (Google Cloud / Firebase)App EngineCannot find module — Cloud Functions: Error: Cannot find module 'X' (dependency missing at runtime) (Google Cloud / Firebase)Cannot find moduleCloud Functions: Build failed — Cloud Functions: Build failed: function.js does not exist / npm install failed with exit code 1 (Cloud Build step) (Google Cloud / Firebase)Cloud Functions: Buil…Cloud Functions: Function execution took 60000 ms, finished with status: timeout — Cloud Functions: Function execution took 60002 ms, finished with status: 'timeout' (Google Cloud / Firebase)Cloud Functions: Func…Cloud Functions: Function failed on loading user code — Cloud Functions: Provided module can't be loaded / Function failed on loading user code. This is likely due to a bug in the user code (Google Cloud / Firebase)Cloud Functions: Func…deploy — Firebase Functions deploy failed: Node runtime/engine unsupported or build error (Google Cloud / Firebase)deploysource upload — Cloud Functions deploy: Could not upload source — storage bucket permission denied (Google Cloud / Firebase)source uploadModuleNot…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.