Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyCharm not exporting the correct requirements.txt

I created a project in PyCharm that uses flask (among a few other modules) installed in a PyCharm-created virutal environment of Python 3.6.1, and the app itself works great in PyCharm. When I went to set up a requirements.txt file for other virtual requirements, however, I noticed that only virtualenv was listed in the output file. (To create the file, I went to "console" and did "pip freeze > requirements.txt".)

After testing some things out, I noticed that pip list only gave me three modules installed to begin with. I know this is not true because when I go into the settings of my interpreter, PyCharm says there are a lot of other modules installed, but it doesn't seem like they're actually installed.

How can I create a requirements file in PyCharm effectively? Do I just have to list all the modules I installed in my readme and have my users figure out how to install them all themselves?

Screenshots below:

Project Settings dialog: Project Settings

Pip list output: pip list

like image 941
Ben Schwabe Avatar asked Aug 03 '17 05:08

Ben Schwabe


1 Answers

Use pipreqs

$ pip install pipreqs
$ pipreqs /home/project/location
Successfully saved requirements file in /home/project/location/requirements.txt

This will export the packages used in your current project directory into requirements.txt

See pipreqs

Why not pip freeze?

  • pip freeze only saves the packages that are installed with pip install in your environment.
  • pip freeze saves all packages in the environment including those that you don't use in your current project. (if you don't have virtualenv)
  • Sometimes you just need to create requirements.txt for a new project without installing modules.
like image 88
Dineshkarthik Raveendran Avatar answered Oct 16 '22 01:10

Dineshkarthik Raveendran