I kept running into the same issue with Python dependencies:
-
pip freezecaptures the entire environment, often hundreds of packages - tools like
pipreqsscan source files, but miss runtime imports
Anything conditional, dynamic, or imported indirectly gets lost.
So I built envcore — a small tool that records dependencies by tracing imports while your code actually runs.
How it works
envcore hooks into Python's import system and logs modules as they are loaded during execution. After the run, it resolves those modules to their corresponding PyPI packages and versions.
envcore trace train.py → env_manifest.json
envcore restore → installs recorded packages
The result is a minimal, runtime-derived manifest.
Example
Instead of exporting a full environment:
numpy 1.26.4
pandas 2.1.4
torch 2.1.0
Only packages that were actually imported during execution are included.
Why runtime tracing
Static analysis misses cases like:
- imports inside conditional branches
- imports inside functions
- dynamic imports (
importlib) - dependencies imported indirectly by other libraries
envcore observes what Python actually loads, so these cases are captured.
Limitation
envcore traces a single execution path. If some code paths are not executed during tracing, their dependencies will not appear in the manifest. The intended usage is to trace a representative run.
Additional features
- resolves import → PyPI package names (e.g.
PIL→Pillow) - works with Jupyter notebooks
- export to requirements.txt, pyproject.toml, Docker, etc.
- CLI + programmatic API
Install
pip install envcore
Top comments (0)