Can pycharm create the requirements.txt file - what am I missing?


Sorry if this seems like it should be so very obvious - I am new to python so your input would be appreciated.

I have a Flask application that I develop with pycharm on a mac/pc - then I want to install it on a raspberry pi and I would like to generate a requirements.txt from the virtual environment that I setup in pycharm.  I dont see how to auto generate that.

What is the best way to create the requirements.txt ( or perhaps ) so that I can copy the application files to the raspberry pi and install all of the necessary dependencies.

Thanks very much for any insight and help you can provide.
Comment actions Permalink
Official comment

Hi Bhavnaberi26! We have a similar feature request, please vote for PY-18847.

Comment actions Permalink
@TheYoungSoul, I dont believe that PyCharm will generate the requirements.txt file for you. The best way to do this is to get pip to do this for you.

pip freeze > requirements.txt
This effectively tells pip to freeze the packages that have been installed into the current environment and output them to stdout (from where they can be redirected to the requirements.txt file).

One thing to be aware of is that pip will list the packages that are installed in the environment where the active version of python is installed.

So if your project has it's own virtual environment (virtualenv) which is separate from the default Python install, and you open a shell and type pip freeze > requirements.txt, without first activating your virtual environment, then you will simply freeze the packages installed in the default Python installation and not the one that is specific to your Flask project.

Whilst PyCharm doesn't output a requirements.txt, if it finds a requirements.txt file in the project root, it will check to ensure that the package requirements are satisfied.

I hope that helps,

Comment actions Permalink
Thanks Bletch.

As a follow up.  I now understand that Pycharm does not directly help me with the generation of the requirements file - so I can stop trying.

I do have a virtual environment that I created when I created my PyCharm project, and I always keep my virtualenvs outside the project ( not sure if that matters ).  

In PyCharm I add modules ( like flask, script, requests, etc ) however, if I just open a shell and activate my virtualenv and type pip freeze just to see what it will return, all it returns is wsgiref==0.1.2 and not any of the modules I added via PyCharm.  PyCharm knows of them - the project works.  

does PyCharm keep its own virtualenv that I need to activate in the shell that is different than the one I thought I was creating when I created the project?

It does seem to me that PyCharm could make this easier since it has all of the info - but I am not complaining.  I love PyCharm.

Thanks again
Comment actions Permalink
@TheYoungSoul, it looks like you hadn't activated the correct virtual environment before typing pip freeze.

You can check the virtual environment that PyCharm is using for your project by visiting the Project Interpreter settings:

File -> Settings -> Project Interpreter

You'll see from the attached image that in my environment, the virtual environment for my project is in



I'm running on Linux so the ~ at the beginning of the path means my home directory.

This means that for me to activate this virtual environment outside of PyCharm, I would need to type

Activating a Virtual Environment in Linux
cd ~/coding/pythontop40
. venv34/bin/activate 
Note that there is a space between the . and the start of the venv34/bin/activate.

Once this command has executed successfully, the $ command prompt should change to have the name of the virtual environment prepended to it - in my case this is (venv34).

If you are on Windows, then you would type something like:

Activating a Virtual Environment in Windows/DOS
cd \users\user\coding\pythontop40
So, if I'm right and you are not activating the same virtual environment that PyCharm is using for your project, and you follow these steps, you should be able to type pip freeze to get the list of currently installed modules for this Python installation.

Result of running pip freeze

Let me know how you go.
Comment actions Permalink

I am having the same difficulty.  Using python 3.4. Virtual env on windows 10.

When I launch the virtualenv and do a pip freeze, I only get the packages that were loaded globally.

I have activated the appropriate virtual environment.  It shows in the parentheses on the left.  Yet, the pip freeze is completely inconsistent with what is displayed in Settings.

Comment actions Permalink

I am also facing the same problem. Every time I add a new package, I have to freeze my packages. This is cumbersome. Is there any alternate so that I can get all the requirements without freezing my packages in Virtual Environment

Comment actions Permalink

I too want Pycharm to automatically create requirements.txt

Comment actions Permalink

I also would like Pycharm to create a requirements based on the active setup.

Beyond that... I would love it if Pycharm could setup a venv base one the current setup

Comment actions Permalink

for anyone still struggling with this there is a simple solution.

in your project view right click on the project root folder and click Open In Terminal

This opens the terminal and activates the Venv.


pip freeze > requirements.txt

you can then close the terminal.

Its not an auto create method but its simple enough.

Comment actions Permalink

I found a way to generate the requirements.txt

install pipreqs --> pip install pipreqs

Then use pipreqs to generate requirments.txt file --> pipreqs <folderlocation>


Please sign in to leave a comment.