Cloud Functions Python: ModuleNotFoundError: No module named 'X' (requirements.txt)
The deployed Python function imports a package that wasn't installed from requirements.txt.
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 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
- Add the package to
requirements.txt - Place
main.pyandrequirements.txtin the deploy root - Pin compatible versions
Detailed fix by platform
Shell
- 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
- requirements.txt — Complete?
- Location — Source root?
- 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:
Similar errors
- App Engine App Engine deploy failed: invalid app.yaml (runtime not supported / entrypoint / handlers)
- Cannot find module Cloud Functions: Error: Cannot find module 'X' (dependency missing at runtime)
- Cloud Functions: Build failed Cloud Functions: Build failed: function.js does not exist / npm install failed with exit code 1 (Cloud Build step)
Most viewed in Google Cloud / Firebase
- Missing or insufficient permissions Firestore: FirebaseError: [code=permission-denied]: Missing or insufficient permissions
- Container failed to start Cloud Run: The user-provided container failed to start and listen on the port defined provided by the PORT=8080 environment variable
- 409: The resource already exists Compute Engine: ERROR: (gcloud.compute.instances.create) Could not fetch resource: The resource 'projects/p/zones/z/instances/vm-1' already exists
Other ways to find it
Where this error sits
Origin: Platform & cloud. Errors that are often confused with or caused by this one (click to open):
🧠 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.
Report a correction or suggest an improvement
Last updated 18 Nov 2026