Answer 1, authority 100%
Using the command:
pip freeze
Answer 2, authority 57%
To get a list of packages in the project, run the command
pip freeze
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
This package works on * nix systems .
Answer 5, authority 4%
There is a Python library pipreqs
to work with requirements.txt
Installation: pip install pipreqs
- Use
pipreqs / path / to / project / folder
- If requirements.txt already exists and needs to be overwritten, then use the
—force
- If you just want to look at the libraries being used without creating, the
—print
to generate requirements.txt
flag
flag
More here
Answer 6
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.
Answer 7
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.