Python Requirements Generator
Paste Python code, from one script or several files, and get the packages it needs as requirements.txt or pyproject.toml dependencies. Standard-library modules are skipped, import names are mapped to the right PyPI packages, such as cv2 to opencv-python and sklearn to scikit-learn, relative and local imports are ignored, and imports inside try blocks or if statements are marked as optional.
- Runs in your browser
- No sign-up
- Free to use
How to use Python Requirements Generator
- Paste your Python code (or open a .py file).
- Add the names of your own modules if they are not detected.
- Choose requirements.txt or pyproject.toml.
- Copy the result and pin versions with pip freeze.
Python Requirements Generator features
Import scanning
import x, from x import y, aliases and importlib calls.
Standard library aware
Python 3.13 module list, with warnings for removed modules.
PyPI name mapping
More than 100 imports whose package names differ.
Local modules ignored
Relative imports, file headers and your own module names.
Optional imports
Imports inside try/if blocks marked as optional.
Two formats
requirements.txt or [project] dependencies.
When to use Python Requirements Generator
- Creating requirements.txt for a script someone sent you.
- Finding the dependencies of an old project without a lock file.
- Preparing a Dockerfile or deployment for a Python app.
- Checking which third-party packages a notebook uses.
Python Requirements Generator FAQ
Why are versions not included?
Import statements do not say which version is used. Install the packages, check that the code works, then run pip freeze to pin exact versions.
Why does cv2 become opencv-python?
The name you import and the name you install often differ. The generator knows the common cases, such as PIL → Pillow, yaml → PyYAML, bs4 → beautifulsoup4 and sklearn → scikit-learn.
How are my own modules excluded?
Relative imports (from .models) are skipped automatically. File headers such as “# utils/helpers.py” mark local modules, and you can list module names in the box.
What are optional imports?
Imports inside a try block or an if statement often provide optional speed-ups or platform-specific features. They are marked so you can decide whether to require them.
What about removed standard modules?
Modules removed in Python 3.12 and 3.13, such as distutils, imp and cgi, are reported so you can replace them.
Is my code uploaded?
No. The scan runs in your browser.
From imports to installable packages
Every third-party import in a Python program corresponds to a package that has to be installed, but the import statements alone do not make a requirements file. Some imports belong to the standard library and need no installation, some refer to your own modules, and many third-party modules are installed under a different name from the one used in import.
The generator reads each line of code and collects module names from import and from statements, including comma-separated imports, aliases and dynamic imports through importlib. Relative imports are skipped because they always refer to your own package. Imports in docstrings are ignored, and imports that are indented, for example inside try or if blocks, are recorded as optional.
Each top-level module name is then classified. Names in the Python 3.13 standard library are skipped, with a warning for modules that recent versions removed, such as distutils, imp, cgi and telnetlib. Names that you list as your own, or that appear in file headers such as “# utils/helpers.py”, are excluded as local code. Everything else is a third-party package.
Finally, import names are translated to the names used on PyPI. Many differ: cv2 comes from opencv-python, PIL from Pillow, yaml from PyYAML, dotenv from python-dotenv, jwt from PyJWT and win32api from pywin32. When several imports come from one package, they are merged into one line, and comments show which imports each package provides.
The output is a starting point. Versions are deliberately not guessed: install the listed packages in a fresh virtual environment, run your code and use pip freeze or a tool such as pip-tools or uv to pin exact versions.