DEV Community

Cover image for pipreqs: Automatically generate python dependencies
Bhupesh Varshney ๐Ÿ‘พ
Bhupesh Varshney ๐Ÿ‘พ

Posted on

pipreqs: Automatically generate python dependencies

I recently found out this alternative method to automatically generate python dependencies for python project management.
It generates requirements.txt file based on the modules & packages you import in your project.
Through this short tutorial I will give you a brief overview on how to use pipreqs.

Installing pipreqs

Installation is pretty straight forward.

pip install pipreqs

Usage

To generate a requirements.txt file run.

pipreqs /<your_project_path>/

pipreqs

You can verify that the requirements.txt appears in the same folder.

pipreqs

You can also list the requirements in command terminal itself by using
--print additional flag.

pipreqs

Also for other options you can always run

pipreqs --help

Here is the help screen

Usage:
    pipreqs [options] <path>

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
    --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.
Enter fullscreen mode Exit fullscreen mode

Why not use pip freeze ?

As the github repo of pipreqs says:

  1. pip freeze saves all packages in the environment including even those that you don't use in your current project.
  2. Also pip freeze is harmful. Read the following post to know more.

Top comments (5)

Collapse
 
ivanlen profile image
Ivan Lengyel

I made a simple wrapper that supports jupyter notebooks also:
pypi.org/project/pipreqsnb/

Collapse
 
codemonk08_ profile image
Mayank Singh

Thanks for this!

Collapse
 
bndr profile image
Vadim Kravcenko

Hi Bhupesh! I was surprised to see my package that I've written sometime ago on dev.to! This makes me happy, glad you enjoyed using it.

Collapse
 
dinhanhx profile image
dinhanhx

Will it work for at least with Python 3.7?

Collapse
 
bhupesh profile image
Bhupesh Varshney ๐Ÿ‘พ

Yes