Reputation: 18467
Title basically says it all. How can I tell pip freeze
to ignore certain packages, like pylint
and pep8
, and their dependencies?
Upvotes: 13
Views: 15867
Reputation: 61
You can now use pip freeze --exclude <package>
, which excludes the specified package from the output. See the documentation.
Upvotes: 6
Reputation: 5658
on windows with powershell:
$exclude = 'pylint', 'pep8'
pip freeze |
Where-Object { $exclude -notcontains $_ } |
ForEach-Object { pip install --upgrade $_ }
Upvotes: 2
Reputation: 339
My approach is the following:
.bashrc
I create the following alias: alias pipfreezeignore='pip freeze | grep -vFxf ignore_requirements.txt'
pip install jedi flake8 importmagic autopep8 yapf
).ignore_requirements.txt
file, as in pip freeze > ignore_requirements.txt
.pip install django
)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.
Upvotes: 13
Reputation: 44112
There are few options available
Simply do not care about these packages being present in pip
output.
Filter the output through some grep
filter and have the result clean.
Note, that pip freeze in virtualenv does not report globally installed packages (however it typically reports argparse
and wsgiref
for me - nothing seems to be really perfect.)
pipwarm
commandwhich would call pip freeze and modify the output as needed (removing unneeded files).
I am aware, I probably did not give you the answer you asked for, but maybe the virtualenv is close to what you need, as it allows global presence of those packages and still allow not having these packages in output of pip freeze.
pep8
and pylint
as scripts but keep them away from pip visibilityIn case, you just care about having pylint
and pep8
available as command line tools, but do not require them visible to pip freeze
, there are multiple options
pep8
and pylint
into virtualenv and copy the scripts to /usr/bin
If you install pylint
and pep8
into separate virtualenv, find location of the executables by which pep8
and which pylint
and copy these files somewhere, where they will be visible, e.g. to /usr/bin
. The scripts you copy or move from virtualenv have hardcoded path to required python packages in the virtualenv and will safely run even when copied (just the scripts, do not touch the rest of related virtualenv). Note, that there is no need to activete given virutalenv to make that working.
pep8
and pylint
system wide but keep developing in virtualenvSystem wide installed command line tools are typically installed into location, which makes them globally visible. At the same time, system wide installed packages are not seen by pip freeze
when called in virtualenv.
Upvotes: 7