pipreqs is a Python utility that automatically generates a `requirements.txt` file for a project based on the import statements found in its Python files and Jupyter notebooks. It aims to create a clean, minimal list of direct dependencies, avoiding the inclusion of unused packages or the entire environment as `pip freeze` does. The current version is 0.5.0, and releases occur irregularly, with significant updates like Jupyter support recently added.
pip install pipreqsNo compatibility data collected yet for this library.
To generate a `requirements.txt` file, navigate to your project's root directory and run `pipreqs .`. If your project includes Jupyter notebooks, use the `--scan-notebooks` flag. You can also preview the requirements without saving by using `--print`.
Ensure your project runs on Python 3.8.1 or newer when using pipreqs v0.5.0+. For older Python versions, use an older pipreqs release.
Always use the `--ignore` option to exclude virtual environment directories, e.g., `pipreqs . --ignore .venv,env`.
Review the generated `requirements.txt` file and manually correct any misidentified packages. Contribute to the `pipreqs` mapping file on GitHub if you find a common error.
After generating the `requirements.txt`, perform a test installation and run your project to identify any missing indirect dependencies or plugins. Add them manually to the `requirements.txt` file.
Use the `--force` flag to explicitly overwrite an existing `requirements.txt` file: `pipreqs . --force`.
Ensure `pipreqs` is installed with `pip install pipreqs`. If installed, try running it via `python -m pipreqs` or add the Python scripts directory to your system's PATH.
Specify the correct encoding for your project's files using the `--encoding` flag, for example: `pipreqs --encoding=utf8 .`
Either update the problematic Python 2 code to Python 3 syntax, or use the `--ignore-errors` flag to skip files with syntax issues, or exclude the directory containing the Python 2 files using `--ignore <dirs>`.
Run `pipreqs .` from your project's root directory to generate `requirements.txt` in the current location. If you want to overwrite an existing file, use `pipreqs . --force`. If specifying a path, ensure it is correct and the directory exists, e.g., `pipreqs /path/to/my/project`.
Upgrade `setuptools` before attempting to install `pipreqs`: `pip install --upgrade setuptools` and then `pip install pipreqs`.