Skip to main content
https://github.com/kactlabs/mod2pip/actions/workflows/tests.yml/badge.svg https://img.shields.io/pypi/v/mod2pip.svg https://codecov.io/gh/kactlabs/mod2pip/branch/master/graph/badge.svg?token=0rfPfUZEAX https://img.shields.io/pypi/l/mod2pip.svg

mod2pip is an enhanced version of pipreqs that generates pip requirements.txt files based on imports in your project. It addresses the main limitations of the original pipreqs by providing:

✅ Enhanced Import Detection - Catches dynamic imports, conditional imports, and late imports that standard tools miss

✅ Conda Environment Support - Properly detects packages in conda environments and custom virtual environments

✅ Transitive Dependencies - Experimental support for resolving indirect dependencies

✅ Better Local Package Detection - Supports editable packages, namespace packages, and non-standard installations

Installation

pip install mod2pip

For minimal installation without Jupyter notebook support:

pip install --no-deps mod2pip
pip install yarg==0.1.9 docopt==0.6.2

Usage

Usage:
    mod2pip [options] [<path>]

Arguments:
    <path>                The path to the directory containing the application files for which a requirements file
                          should be generated (defaults to the current working directory)

Options:
    --use-local           Use ONLY local package info instead of querying PyPI
    --pypi-server <url>   Use custom PyPi server
    --proxy <url>         Use Proxy, parameter will be passed to requests library
    --debug               Print debug information
    --ignore <dirs>...    Ignore extra directories, each separated by a comma
    --no-follow-links     Do not follow symbolic links in the project
    --encoding <charset>  Use encoding parameter for file open
    --savepath <file>     Save the list of requirements in the given file
    --print               Output the list of requirements in the standard output
    --force               Overwrite existing requirements.txt
    --diff <file>         Compare modules in requirements.txt to project imports
    --clean <file>        Clean up requirements.txt by removing modules that are not imported in project
    --mode <scheme>       Enables dynamic versioning with <compat>, <gt> or <no-pin> schemes
                          <compat> | e.g. Flask~=1.1.2
                          <gt>     | e.g. Flask>=1.1.2
                          <no-pin> | e.g. Flask
    --scan-notebooks      Look for imports in jupyter notebook files
    --enhanced-detection  Enable enhanced import detection (dynamic imports, conda packages)
    --include-transitive  Include transitive dependencies (experimental)
    --transitive-depth <n> Maximum depth for transitive dependency resolution (default: 2)

Enhanced Features

Dynamic Import Detection

mod2pip can detect imports that traditional tools miss:

# Dynamic imports
module_name = "pandas"
pd = importlib.import_module(module_name)

# Conditional imports
try:
    import tensorflow as tf
except ImportError:
    tf = None

# Late imports in functions
def process_data():
    import scipy.stats as stats
    return stats.norm()

Conda Environment Support

Works seamlessly with conda environments and detects conda-installed packages that pip-based tools often miss.

Enhanced Usage Examples

# Basic usage with enhanced detection
mod2pip --enhanced-detection

# Include transitive dependencies
mod2pip --enhanced-detection --include-transitive

# Use only local packages (faster, no PyPI queries)
mod2pip --enhanced-detection --use-local

# Print to stdout instead of file
mod2pip --enhanced-detection --print

Example Output

$ mod2pip --enhanced-detection /home/project/location
INFO: Using enhanced detection for conda packages and dynamic imports
Successfully saved requirements file in /home/project/location/requirements.txt

Contents of requirements.txt

beautifulsoup4==4.14.3
numpy==2.4.0
pandas==2.3.3
requests==2.32.5
tensorflow==2.20.0

Why mod2pip over pip freeze?

  • pip freeze only saves packages installed with pip install in your environment

  • pip freeze saves ALL packages in the environment, including unused ones (without virtualenv)

  • pip freeze misses packages installed via conda or other package managers

  • pip freeze cannot detect dynamically imported packages

  • mod2pip analyzes your actual code imports and generates minimal, accurate requirements

Why mod2pip over pipreqs?

  • Better Import Detection: Catches dynamic imports, conditional imports, and late imports

  • Conda Support: Works properly with conda environments and conda-installed packages

  • Transitive Dependencies: Optional resolution of indirect dependencies

  • Enhanced Local Detection: Supports editable packages, namespace packages, and custom installations

  • More Accurate: Reduces “missing packages” issues common with pipreqs

Metadata

Release files for mod2pip 0.11.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mod2pip 0.11.0
File Size Uploaded
mod2pip-0.11.0.tar.gz 54.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mod2pip 0.11.0
File Interpreter ABI Platform
mod2pip-0.11.0-py3-none-any.whl Python 3 none any Details

Total release size: 98.6 kB

Release files / mod2pip-0.11.0.tar.gz

Download URL mod2pip-0.11.0.tar.gz
Size 54.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e6459c188dbd9632d0c17c37838f9f9506ebb384ce9002a6f3d7c56e5832451d
BLAKE2b-256 checksum
How to use checksums
e3190be13d7c84d1448608c5c5e6440c7ac24457c6d8219f0126b9ee833cbbde
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release files / mod2pip-0.11.0-py3-none-any.whl

Download URL mod2pip-0.11.0-py3-none-any.whl
Size 43.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cca6f60da1b981f74161c6f2992c4007d722d8f9efbd4e3430b5ae18a26ca582
BLAKE2b-256 checksum
How to use checksums
4ef48d1308488946b5bf01c95f060d220725928a33607eef6c913323c79f8f67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release history Release notifications | RSS feed

This release

0.11.0 This release

2 release files

0.10.0

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page