TRICK: Easy requirements build

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

Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

or, if you use Python3:

$ pip3 install pipreqs --user

Enter fullscreen mode Exit fullscreen mode

To build automatically your requirements.txt, just run the following command in the project directory:

$ pipreqs

Enter fullscreen mode Exit fullscreen mode

or

$ pipreqs /project/location

Enter fullscreen mode Exit fullscreen mode

And the magic will happen!!

图片[1]-TRICK: Easy requirements build - 拾光赋-拾光赋
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

pip install pipreqs

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:

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

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


View on GitHub

原文链接:TRICK: Easy requirements build

© 版权声明
THE END
喜欢就支持一下吧
点赞11 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容