BlogPython

ModuleNotFoundError: No module named 'requests' How to fix it.

Your code imports a Python package that is not listed in requirements.txt. Add it, and use the package name, which can differ from the import name.

How the Agent API works
What you see
Traceback (most recent call last):
  File "app.py", line 1, in <module>
    import requests
ModuleNotFoundError: No module named 'requests'
  • What it meansAn import has no installed package
  • The fixAdd the package to requirements.txt
  • Watch outImport names differ from package names
  • OrA local file was not sent

What it means

Your code imports a module, and nothing on the server provides it. The server installs only what requirements.txt lists. The package is probably installed on your own computer, in your virtual environment or globally, and was never written into the file.

How to fix it

  1. Find the package name

    Ask your agent: "Which pip package provides this import?" It is often the same name, but not always.

  2. Add it to requirements.txt

    Add the package name, and a version if you want to pin it. Commit the file.

  3. Deploy again

    A failed deploy never counts against your plan.

Import names that differ from package names

  • import cv2 comes from opencv-python.
  • import PIL comes from pillow.
  • import yaml comes from pyyaml.
  • import sklearn comes from scikit-learn.
  • import bs4 comes from beautifulsoup4.
  • import dotenv comes from python-dotenv.

When the module is your own file

If the missing module is a file in your project, such as from app.utils import helper, check two things. The file must be committed and sent. The folder needs an __init__.py if your code needs one. Also check how the app is started: the folder it runs from decides what Python can import.

01Questions

Python import questions, answered.

Anything else? Write to us and a person answers.

support@antideploy.com
Why does it work on my machine?

Your machine has packages installed that the project never listed. A clean server has only what requirements.txt says.

How do I list everything I use?

Ask your agent to compare your imports with requirements.txt, or run pip freeze in your working environment and keep the packages your code uses.

Does this failed deploy cost anything?

No. Failed deploys never count against your plan.

Deploy something. Start with one sentence.

Paste one sentence into your coding agent, click Approve once, and get a live link. No card, no trial clock.

Start from GitHub or a folder
Prompt copied Paste it into Claude Code, Codex or Cursor and press Enter.