Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore certain packages and their dependencies with pip freeze

Tags:

python

pip

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

like image 364
Two-Bit Alchemist Avatar asked May 13 '14 19:05

Two-Bit Alchemist


People also ask

Does pip freeze include dependencies?

pip freeze might seem very useful initially but it can mess up your project because of the following reasons: It dumps all the libraries installed in your project including dependencies and sub-dependencies in the requirements.

How do I freeze requirements for pip?

The recommended approach is to use a requirements. txt file (readthedocs.org) that contains a list of commands for pip that installs the required versions of dependent packages. The most common command is pip freeze > requirements. txt , which records an environment's current package list into requirements.

How do you unfreeze pip?

You just need to delete the venv folder and initialize new one.

What is conda equivalent of pip freeze?

pip freeze , like conda list --export , is more for generating requirements files for your environment. For example, if you have created a package in your customized environment with certain dependencies, you can do conda list --export > requirements.


1 Answers

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.

like image 156
Martí Bosch Avatar answered Sep 25 '22 15:09

Martí Bosch