Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
556 views
in Technique[技术] by (71.8m points)

python - Ignore certain packages and their dependencies with pip freeze

Title basically says it all. How can I tell pip freeze to ignore certain packages, like pylint and pep8, and their dependencies?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

My approach is the following:

  1. I my .bashrc I create the following alias: alias pipfreezeignore='pip freeze | grep -vFxf ignore_requirements.txt'
  2. Create the virtual environment, and install first all the packages that I do not want to keep track of (i.e. pip install jedi flake8 importmagic autopep8 yapf).
  3. Immediately save them in a ignore_requirements.txt file, as in pip freeze > ignore_requirements.txt.
  4. Install the rest of packages (e.g. pip install django)
  5. Use pipfreezeignore > requirements.txt (in the same folder where ignore_requirements.txt is) so I just get in requirements.txt the installed packages that are not in ignore_requirements.txt

If you always want to ignore the same packages (through all your virtual environments), you might redefine the alias as in alias pipfreezeignore='pip freeze | grep -vFxf /abs/path/to/ignore_requirements.txt' Just make sure that no packages from ignore_requirements.txt are not actually necessary for your project.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...