Registry / devops / pipreqs

pipreqs

JSON →
library0.5.0pypypiunverified

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 pipreqs
INSTALL
IMPORT
SIG · PIPREQS
P
pipreqs
devopspythonv0.5.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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`.

# Navigate to your project's root directory # Generate requirements.txt for Python files: pipreqs . # Generate requirements.txt including Jupyter notebooks: pipreqs . --scan-notebooks # To print to console without saving to file: pipreqs . --print
pipreqs --version
Debug
Known issues
breakingPython version compatibility has changed. Older versions of pipreqs supported Python 3.7+, but as of v0.5.0, it requires Python >=3.8.1.
fix
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.
affects: <0.5.0
gotchapipreqs may include irrelevant packages if virtual environment folders (`.venv`, `env`, etc.) are not explicitly ignored, as it scans all `.py` files in the specified path.
fix
Always use the `--ignore` option to exclude virtual environment directories, e.g., `pipreqs . --ignore .venv,env`.
affects: All
gotchaModule-to-package mapping issues can lead to incorrect or missing package names (e.g., `kafka` instead of `kafka-python`, or `azure` modules). While mappings are frequently updated, manual intervention may sometimes be necessary.
fix
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.
affects: All
gotchapipreqs primarily detects direct imports. It may not include indirect dependencies (packages required by your direct imports but not explicitly imported in your code) or specific plugins that are only used implicitly.
fix
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.
affects: All
gotchaBy default, pipreqs will not overwrite an existing `requirements.txt` file, preventing accidental data loss.
fix
Use the `--force` flag to explicitly overwrite an existing `requirements.txt` file: `pipreqs . --force`.
affects: All
Errors
Common errors & fixes
'pipreqs' is not recognized as an internal or external command, operable program or batch file
The `pipreqs` executable is not found in your system's PATH environment variable, typically meaning it was not installed correctly or its installation directory is not accessible.
fix
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.
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position ...
Pipreqs encountered a Python file containing non-ASCII characters that it could not decode using its default (or inferred) encoding, often 'ascii' or 'cp1252'.
fix
Specify the correct encoding for your project's files using the `--encoding` flag, for example: `pipreqs --encoding=utf8 .`
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
Pipreqs attempted to parse a Python file within your project that contains Python 2-style syntax (like `print` statements without parentheses) while running in a Python 3 environment.
fix
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>`.
No such file or directory: '.../requirements.txt'
This error occurs when `pipreqs` is run without specifying a target directory, or the specified directory does not exist, or it attempts to write to a location that doesn't exist or isn't writable, or an existing `requirements.txt` file is expected but not found.
fix
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`.
ERROR: Can not execute `setup.py` since setuptools is not available in the build environment.
During the installation of `pipreqs` (or one of its dependencies), the `setuptools` package, which is necessary for building Python packages, was either missing or outdated in the installation environment.
fix
Upgrade `setuptools` before attempting to install `pipreqs`: `pip install --upgrade setuptools` and then `pip install pipreqs`.
Upgrade
Version history
0.5.0latest on PyPI · released Feb 18, 2024
Audit
Dependencies
docoptrequiredCommand-line argument parser.
ipythonoptionalRequired for Jupyter notebook scanning functionality.
nbconvertoptionalRequired for Jupyter notebook scanning functionality.
yargrequiredUsed for argument parsing.
Agent activity
3 hits · last 30 days
node
2
Resources
pipreqs — pip install pipreqs · libregistry