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

- 115,751
- 26
- 228
- 437

- 6,193
- 8
- 41
- 79
-
15`pip freeze > requirements.txt`? – jonrsharpe Apr 18 '15 at 09:16
-
@jonrsharpe If he is using virtual environment. – khajvah Apr 18 '15 at 09:42
-
@khajvah PyCharm makes it very easy to set up and use a new virtualenv when you create a new project, so I don't see why they wouldn't be. – jonrsharpe Apr 18 '15 at 09:44
-
6`pip freeze > requirements.txt` will output all installed packages, but i would like only the project-related. – chenzhongpu Apr 18 '15 at 10:01
-
No, there is nothing that can magically detect what packages you want to use. You have to tell that to the system yourself, by using a virutal environment or by writing the requirements.txt by hand. – Klaus D. Apr 18 '15 at 10:04
-
4@ChenZhongPu then you should set up a project-specific `virtualenv` and install only what that project needs. See https://www.jetbrains.com/pycharm/help/creating-virtual-environment.html. `pip freeze` *within that environment* will then create the list you want. – jonrsharpe Apr 18 '15 at 10:43
-
Possible duplicate of [Automatically create requirements.txt](https://stackoverflow.com/questions/31684375/automatically-create-requirements-txt) – gmauch Mar 20 '18 at 13:58
-
Possible duplicate of [How to create a requirements.txt?](https://stackoverflow.com/questions/29938554/how-to-create-a-requirements-txt) – Daniel Santos Apr 02 '18 at 13:07
-
There is propably a BUG in PyCharm - https://youtrack.jetbrains.com/issue/PY-41953 – Rohlik Feb 13 '21 at 20:47
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. – Alexander Zhak Apr 18 '15 at 15:21
-
7Sorry - 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. – jsbueno Apr 18 '15 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 S May 03 '17 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? – gented Nov 15 '19 at 00: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. – jsbueno Nov 15 '19 at 01:43
-
I agree, but this should be specified in the answer, because it makes all the difference. The answer as it is by itself has no mention of it. – gented Nov 15 '19 at 08:42
-
yes. but sometimes, being able to type in a short answer that helps the OP is nice as well. Other than that, I hereby invite you to edit this answer and expand it however you like. You are welcome. – jsbueno Nov 15 '19 at 15:34
-
using the stated command in the terminal gives me an error: "NotADirectoryError: [WinError 267] The directory name is invalid". supposedly you need a virtualenv set up before this. would be nice to see that mentioned somewhere – Roly Poly Jun 29 '20 at 03:56
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.

- 6,873
- 11
- 48
- 102
-
1best answer hands down. for anyone who needs it fast: "pip install pigar " and then "pigar" (in the project root) – Chris Oct 02 '19 at 08:10
-
open the terminal in Pycharm and type in this command:
pip freeze > requirements.txt
and the requirements.txt will be automatically created

- 149
- 2
- 6
-
1This should be the one answer to have more votes. It is exactly as it works. – Netwave Dec 01 '18 at 04: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 :)

- 109
- 1
- 3
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

- 1,502
- 18
- 17
-
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. – Anum Sheraz Jan 21 '19 at 20:42