Answer 1, authority 100%
Using the command:
Answer 2, authority 57%
To get a list of packages in the project, run the command
To write the output to requirements.txt, add the following:
pip freeze & gt; requirements.txt
Execute the command at the root of the project. The file will also appear there. This assumes the use of an active venv for the current project. When running outside the virtual environment of the current project, unnecessary packages not related to the current project may be pulled!
Answer 3, authority 29%
It’s best to look at INSTALLED_APPS and pick everything out manually. With
pip freeze there is an option to get a pumpkin after a while, because it pulls absolutely all packages along with their dependencies (including system ones), and packages are updated over time, old versions are removed. And you don’t have to manage dependencies manually – this is the task of the package manager (pip or easy_install).
It is best to fill in the requirements file as you write the project, not after.
Added: pip has a suitable option:
pip freeze --local .
From Help: If in a virtualenv that has global access, do not output globally-installed packages.
Answer 4, authority 18%
To create a
requirements.txt or update an existing file to match the current virtualenv, you can use
pip-dump command :
$ pip install pip-tools $ pip-dump
Answer 5, authority 4%
There is a Python library
to work with requirements.txt
pip install pipreqs
pipreqs / path / to / project / folder
- If requirements.txt already exists and needs to be overwritten, then use the
- If you just want to look at the libraries being used without creating, the
to generate requirements.txt
Chet first read in Russian and began to answer in English. Well, a little magic if there is no venv
If you have little project THIS will do some magic
for i in `cat * .py | grep -R import | sort | uniq | sed 's / ^ import //; s / ^ from //; s / import. * // '`; do python -m pip freeze --local | grep -i $ i; done
You should check it, but it work.
It goes through all the files, collects imports and clicks on the installed packages, of course it does not look for a full match, so there will be unnecessary ones, but not many.
If you are working in PyCharm, you can generate requirements.txt based on the current project: https://www.jetbrains.com/help/pycharm/managing-dependencies.html . Convenient, since only packages that are used in the project are added.
There may be a similar tool in another IDE you are using.