Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to output requirements.txt automatically?

I want to output the requirements.txt for my Python 3 project in PyCharm. Any ideas?

like image 828
chenzhongpu Avatar asked Apr 18 '15 09:04

chenzhongpu


4 Answers

Try the following command:

pip freeze > requirements.txt
like image 68
3 revs, 3 users 44% Avatar answered Nov 15 '22 14:11

3 revs, 3 users 44%


Pigar works quite well I just tested it

https://github.com/damnever/pigar

The answer above with pip freeze will only work properly if you have set up a virtualenv before you started installing stuff with pip. Otherwise you will end up with requirements which are "surplus to requirements". It seems that pigar goes and looks at all your import statements and also looks up the versions currently being used. Anyway, if you have the virtualenv set up before you start it will all be cleaner, otherwise pigar can save you. It looks in subdirectories too.

like image 26
cardamom Avatar answered Nov 15 '22 16:11

cardamom


open the terminal in Pycharm and type in this command:

pip freeze > requirements.txt

and the requirements.txt will be automatically created

like image 6
vbid Avatar answered Nov 15 '22 16:11

vbid


Surely this post is a bit old but the same I contribute with what I learned, to generate the requirements.txt we can do it in three ways, as far as I know:

  1. using FREEZE

pip freeze > requirements.txt

Before running the command be sure that the virtual environments is activated because the command will be executed in the same folder as the project.A file requirements.txt with Python dependencies will be generated in the same folder as the execution. If you use this command all requirements will be collected from the virtual environment. If you need to get requirements used only in the current project scope then you need to check next options.


  1. using DEEPHELL

pip install --user dephell


  1. using PIPREQS

pip install pipreqs

pipreqs /path/to/project


Note

Why to use pipreqs? Because pip freeze will collect all dependencies from the environments. While pipreqs will collect requirements used only in the current project!

plus freeze only saves the packages that are installed with pip install and saves all packages in the environment.

If you like to generate requirements.txt without installing the modules use pipreqs

If there were other ways to do it always grateful to continue learning :)

like image 5
ElAgus Avatar answered Nov 15 '22 15:11

ElAgus