A few days ago I was doing a project in Python and wanted to let it practice for anyone who wanted to access it, and one of the steps for that was to build the requirements.txt, that commonly loads the necessary packages to run the projects in Python and the easiest alternative is:
- view the packages in the project;
- select the packages after executing:
$ pip freeze
But that's not practical at all, so I looked for an alternative that would meet my need, and found a project that did just that. Its goal is generate requirements.txt based on imports in project.
To install this package, just run:
$ pip install pipreqs --user
or, if you use Python3:
$ pip3 install pipreqs --user
To build automatically your requirements.txt, just run the following command in the project directory:
$ pipreqs
or
$ pipreqs /project/location
And the magic will happen!!
I hope this post helped and feel free to get in touch! ;)
Thanks for reading!
This post is inspired by the following repository:
bndr / pipreqs
pipreqs - Generate pip requirements.txt file based on imports of any project. Looking for maintainers to move this project forward.
pipreqs
- Generate requirements.txt file for any project based on imports
Installation
Obs.: if you don't want support for jupyter notebooks, you can install pipreqs without the dependencies that give support to it. To do so, run:
Usage
Usage
pipreqs [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. You can also just set the
environments parameter in your terminal:
$ export HTTP_PROXY="http://10.10.1.10:3128"
$ export HTTPS_PROXY="https://10.10.1.10:1080"
--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
…
Top comments (0)