How to create a requirements.txt?
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
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, 2022Comments
-
Daniel Santos almost 2 years
I'm wondering how I can create a suitable requirements.txt for my Python 3 application?
-
Eloims about 9 yearsThis answer will work assuming you are using virtualenv.
-
Paco about 9 yearsIt will work even if not using a
virtualenv
, but it will list all packages installed on the system with pip -
Yauheni Leaniuk about 3 yearsThanks! 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 almost 3 yearsEven 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 over 2 yearsThis doesn't catch all possible cascading dependencies for my Cython lib, but it's the starting point I needed. Thanks.
-
jspinella almost 2 yearsTo be clear you simply install pigar and run
pigar
in the local directory of the python file you want the requirements.txt for