Title basically says it all. How can I tell pip freeze
to ignore certain packages, like pylint
and pep8
, and their dependencies?
问题:
回答1:
There are few options available
Try simple ignorance
Simply do not care about these packages being present in pip
output.
Delete these lines from output
Filter the output through some grep
filter and have the result clean.
Use virtualenv and do not install unwanted packages into it
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.)
Write your own pipwarm
command
which 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.
Install pep8
and pylint
as scripts but keep them away from pip visibility
In 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
Install 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.
Install pep8
and pylint
system wide but keep developing in virtualenv
System 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.
回答2:
My approach is the following:
- I my
.bashrc
I create the following alias:alias pipfreezeignore='pip freeze | grep -vFxf ignore_requirements.txt'
- 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
). - Immediately save them in a
ignore_requirements.txt
file, as inpip freeze > ignore_requirements.txt
. - Install the rest of packages (e.g.
pip install django
) - Use
pipfreezeignore > requirements.txt
(in the same folder whereignore_requirements.txt
is) so I just get inrequirements.txt
the installed packages that are not inignore_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.
回答3:
on windows with powershell:
$exclude = 'pylint', 'pep8'
pip freeze |
Where-Object { $exclude -notcontains $_ } |
ForEach-Object { pip install --upgrade $_ }