How to create a requirements.txt?

55,480

Solution 1

type following line in your command prompt

pip freeze > requirements.txt

Solution 2

There's a module called pipreqs which is designed for creating the requirements file.

pip install pipreqs
pipreqs /GitHub/FolderName #Insert path to file

Add the location to the folder where the python files reside. Pipreqs will create a requirements.txt file in the folder.

Solution 3

if you aren't in virtualenv and don't feel like putting all your installed packages in the requirements file like the accepted answer. just use pigar

Share:
55,480
Daniel Santos
Author by

Daniel Santos

Experienced Software Engineer with a demonstrated history of working in the consumer electronics and medical devices industry. Skilled in C++, Python, JavaScript, IoT, Machine Learning, web and mobile development, and others. Strong engineering professional with a Bachelor’s Degree focused in Computer Science from the University of Massachusetts Lowell.

Updated on July 09, 2022

Comments

  • Daniel Santos
    Daniel Santos almost 2 years

    I'm wondering how I can create a suitable requirements.txt for my Python 3 application?

  • Eloims
    Eloims about 9 years
    This answer will work assuming you are using virtualenv.
  • Paco
    Paco about 9 years
    It will work even if not using a virtualenv, but it will list all packages installed on the system with pip
  • Yauheni Leaniuk
    Yauheni Leaniuk about 3 years
    Thanks! This also works great (it doesn't add all the libraries in a machine, but only those used in the folder), even if you don't have a virtual environment!
  • Kifsif
    Kifsif almost 3 years
    Even if it works, it is too clumsy and blotted. Suppose you have 100 libraries you need in a project. And with 3 dependencies each. Will you be able to manage your requirements.txt?
  • Phlucious
    Phlucious over 2 years
    This doesn't catch all possible cascading dependencies for my Cython lib, but it's the starting point I needed. Thanks.
  • jspinella
    jspinella almost 2 years
    To be clear you simply install pigar and run pigar in the local directory of the python file you want the requirements.txt for