简体   繁体   中英

Creating a requirements.txt file

When uploading to GitHub one would want to include a requirements.txt file. I have created a virtual environment and so pip3 freeze lists only the packages I installed during the project development. However I had also installed pylint (suggested by VS Code) which I wouldn't want on the requirements file. Pylint isn't listed in a single entry when I use pip3 freeze. So is there any way to remove pylint and related stuff from the requirements? Worst case can anyone list out all the pylint stuff so I can manually remove them from requirements file?

Assuming you're using pip (and not other manager like Poetry), you can use pip-tools to handle this scenario. First you write your requirements manually into a file:

$ cat requirements.in

# assuming your project uses only following dependencies
django
gunicorn

then you can generate the whole dependency graph:

$ pip-compile requirements.in

#
# This file is autogenerated by pip-compile
# To update, run:
#
#    pip-compile requirements.in
#
asgiref==3.2.10           # via django
django==3.1               # via -r requirements.in
gunicorn==20.0.4          # via -r requirements.in
pytz==2020.1              # via django
sqlparse==0.3.1           # via django

^ this is your requirements.txt for production. For the development dependencies you can do the same, but save them into a separate file, so you can install it when needed, but it stays separated from runtime dependencies:

$ cat requirements-dev.in

# development requirements
pylint
mypy
pytest

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM