Domanda

I'm working on a Python library, which I have installed in my local virtualenv for testing. I have several dependencies installed with pip. When I do

$ pip freeze > requirements.txt

it adds my current project like so:

-e git+git@github.com:path/to/my/project@somehash#egg=lib-master

Which I have to manually remove - my project doesn't actually depend on itself. Is it possible to pass a parameter to pip that says, "Hey, ignore this/these kinds of packages?"

È stato utile?

Soluzione

The simplest solution would be to pipe the result of pip freeze to grep with -v (invert-match):

pip freeze | grep -v 'project_name' > requirements.txt

Demo:

$ mkvirtualenv test
New python executable in test/bin/python
Installing Setuptools...done.
Installing Pip...done.
(test)$ pip freeze
wsgiref==0.1.2
(test)$ pip install requests
Downloading/unpacking requests
  Downloading requests-2.2.1.tar.gz (421kB): 421kB downloaded
  Running setup.py egg_info for package requests

Installing collected packages: requests
  Running setup.py install for requests

Successfully installed requests
Cleaning up...
(test)$ pip freeze
requests==2.2.1
wsgiref==0.1.2
(test)$ pip freeze | grep -v 'requests'
wsgiref==0.1.2
(test)$ pip freeze | grep -v 'requests' > requirements.txt
(test)$ cat requirements.txt 
wsgiref==0.1.2

Also see: Negative matching using grep (match lines that do not contain foo).

Hope that helps.

Altri suggerimenti

This is wrong question. You should not try to establish requirements based on what you have installed in the moment. Your project should specify its requirements and based on this information (and requirements of requirements) the final set of requirements should be calculated. Please note, that development requirements should be specified as such so that they could be installed separately as needed – see Setuptools “development” Requirements and How to customize a requirements.txt for multiple environments?.
Unfortunately pip is not able to calculate this yet. You can calculate this using pip-tools which will write the result into requirements.txt file. See my answer for complete example how to use pip-tools.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top