I'm wondering how I can create a suitable requirements.txt for my Python 3 application?
Asked
Active
Viewed 8.6k times
3 Answers
94
type following line in your command prompt
pip freeze > requirements.txt

Pawan
- 4,249
- 6
- 27
- 32
-
13This answer will work *assuming you are using virtualenv*. – Eloims Apr 29 '15 at 08:44
-
27It will work even if not using a `virtualenv`, but it will list all packages installed on the system with pip – Paco Apr 29 '15 at 08:46
-
1Even 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? – Kifsif May 16 '21 at 10:14
45
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.

siddhantsomani
- 1,324
- 13
- 12
-
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! – Yauheni Leaniuk Mar 31 '21 at 10:55
-
1This doesn't catch all possible cascading dependencies for my Cython lib, but it's the starting point I needed. Thanks. – Phlucious Aug 18 '21 at 23:12
5
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

0xMH
- 1,825
- 20
- 26
-
To be clear you simply install pigar and run `pigar` in the local directory of the python file you want the requirements.txt for – jspinella May 18 '22 at 17:53