Programming with AI
ENRU
2.11

Dependencies

what is imported, from where, and in which version

What it is

Dependencies are other people's code that your project uses. Reading them matters for two reasons: the imports tell you what a file is in the business of doing, and the versions explain why AI-written code might not run.

The second reason is exactly reason 3 from article 3.1, "it remembers something else". Half of all unexplained errors in generated code come down to a version.

What it looks like in code

import os                          # standard library
import sqlite3

import aiohttp                     # external, from requirements
from aiogram import Bot, Router
from aiogram.filters import Command

from config import settings        # ours, from this project
from storage import add_reminder

Three groups separated by blank lines: standard library, external packages, own code. This is the conventional order, and it shows at a glance what comes from where.

How to tell them apart

SignWhere it comes from
os, sys, json, re, datetime, pathlibstandard library, nothing to install
listed in requirements.txtan external package
matches a file or folder name in the projectyour own code

If you are not sure, look in requirements.txt. What isn't there and doesn't look like a project file is most likely from the standard library.

Two forms of import

import sqlite3              # take the whole module
conn = sqlite3.connect(...)

from aiogram import Bot     # take one name out of the module
bot = Bot(token=...)

The only difference is how you refer to things afterwards. The form from ... import * is bad: it is unclear which names appeared in the file, and they can shadow existing ones.

Where the versions are written

measured
aiogram==3.13.1
aiohttp>=3.9,<4.0
python-dotenv
  • ==3.13.1 — exactly this version.
  • >=3.9,<4.0 — anything in that range.
  • nothing specified — anything, including a release that comes out tomorrow and is incompatible.

The last case is the source of "it worked yesterday" errors. Which is why working projects pin their versions.

To find out what is actually installed:

pip freeze | grep aiogram

Why the version decides so much

Across major versions, libraries break compatibility. The examples you will meet most often:

LibraryWhat changed
aiogram 2 → 3different handler registration, different imports
pydantic 1 → 2different method names, different validation
React (classes → hooks)an entirely different way of writing components
Flutterchanges its API across major versions

There is more code for the old versions on the internet, so the AI reaches for it by default.

What to tell the AI

Prompt
Here is my requirements.txt. Write code only for these versions.

aiogram==3.13.1
aiohttp==3.9.5

When the code won't run:

Prompt
The code fails: ImportError: cannot import name 'Dispatcher'
from 'aiogram'. I have aiogram 3.13.1. Which version was this
written for, and how do I rewrite it for mine?

Before adding a new library:

Prompt
Can this be solved with the standard library, without a new
dependency? If not, explain why.

That last question is worth asking every time. Every dependency is something to keep updated, something that can break, and something that makes the project bigger.

What to look for

An import that isn't in requirements.txt. The code will not run on your machine even though it "works" for the AI. Checked instantly: try running it.

An invented library. The AI sometimes imports packages that do not exist, or methods a package does not have. The check is pip index versions <name> or simply a search in the documentation (article 4.8).

A new dependency for one function. A whole package to format a date is almost always too much.

An import inside a function. Sometimes justified (a slow library, circular imports), but more often it is a scar from edits. If you spot one, ask why.

Versions that have drifted apart. requirements.txt says one thing, pip freeze shows another. The environment was not built from that file, and your machine and the server may differ.

Cheat sheet

  • Three groups of imports: standard · external · your own.

  • Not sure where something comes from — check requirements.txt.

  • == pins the version; nothing specified means anything, and that is risky.

  • Always name the library version in the prompt.

  • Half of the strange errors in AI code are a version problem.

  • Before a new dependency, ask whether you can do without it.