I want to output the requirements.txt
for my Python 3 project in PyCharm. Any ideas?
5 Answers
Try the following command:
pip freeze > requirements.txt
-
18This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. Commented Apr 18, 2015 at 15:21
-
8Sorry - this does provide an answer to the question. It can be expanded, of course - as can be seen in the comments it is not the desired solution. But this single line typed in the prompt will "output requirements.txt automatically" as asked for.– jsbuenoCommented Apr 18, 2015 at 15:41
-
8I think the author asked for a way to do it in PyCharm. This command would work, but unless it can be used within the PyCharm context than I don't think it answers the question– Jad SCommented May 3, 2017 at 15:31
-
6Why is this answer even upvoted?
pip freeze
just lists all installed packages and has nothing to do with the requirements for a project. Why is this answer all over the place?– gentedCommented Nov 15, 2019 at 0:07 -
The installed packages in a given environment are the ones your project should need. If you are working in a large, or even a medium project, and have not isolated it in a virtualenv, you are doing it wrong. You will have to separate the "development" requirements and running requirements manually, of course.– jsbuenoCommented Nov 15, 2019 at 1:43
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.
-
1best answer hands down. for anyone who needs it fast: "pip install pigar " and then "pigar" (in the project root)– ChrisCommented Oct 2, 2019 at 8:10
-
open the terminal in Pycharm and type in this command:
pip freeze > requirements.txt
and the requirements.txt will be automatically created
-
1This should be the one answer to have more votes. It is exactly as it works.– NetwaveCommented Dec 1, 2018 at 4:46
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:
- 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.
- using DEEPHELL
pip install --user dephell
- 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 :)
You can do it in Pycharm by going to Settings and project interpreter. Select all the Packages with their Version and latest. Then copy all this data into a MS word document. The MS word will treat it as a table. Delete the middle column of this table. Now copy all this data into a notepad++. Search for double spaces ' ' or a tab and replace it with '=='. Save this file as a requirements.txt
. It will work
-
1trying other solutions
pip freeze > requirements.txt
creates a BIG requirement.txt file including every single (including default) packages. I only wanted to get custom packages which I installed later inside my vertenv. So this HACK worked for me. Commented Jan 21, 2019 at 20:42
pip freeze > requirements.txt
?pip freeze > requirements.txt
will output all installed packages, but i would like only the project-related.virtualenv
and install only what that project needs. See jetbrains.com/pycharm/help/creating-virtual-environment.html.pip freeze
within that environment will then create the list you want.