3

I have one virtual environment, where elasticsearch python package was installed.

I want to find, which package has dependency on elasticsearch and did installation in virtual environment.

(.venv)root@test:~# pip freeze | grep elast
elasticsearch==1.4.0.dev0

I tried some solution from show reverse dependencies with pip? but its not worked

(.venv)root@test:~# python
Python 2.7.8 (default, Oct 18 2014, 12:50:18)
[GCC 4.9.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pip
>>> package_name = 'elasticsearch'
>>> rev_dep = [pkg.project_name for pkg in pip.get_installed_distributions() if package_name in [requirement.project_name for requirement in pkg.requires()]]
>>> rev_dep
[]
>>>

Path of module return virtual env path.

(.venv)root@test:~# python -c 'import elasticsearch; print elasticsearch.__path__'
['/opt/venvs/.venv/local/lib/python2.7/site-packages/elasticsearch']

I have doubt that elasticsearch debian package might be installed this python package, but not sure.

(.venv)root@test:~# dpkg -l | grep elast
ii  elasticsearch                        1.2.0                           all          Open Source, Distributed, RESTful Search Engine
1
  • 1
    First, check where elasticsearch is installed (so you can know whether you're using the system package or not). Please provide the output of: python -c 'import elasticsearch; print elasticsearch.__path__'. Jan 29, 2015 at 12:30

1 Answer 1

2

Step 1. find your site-packages directory for your virtualenv:

Note my shell prompt showing venv38 and the egrep at the end.

(venv38) myuser@foo$ python -m site | egrep venv38

The site.py module has all sorts of interesting info, but we are only interested in the venv's site-package.

Output:

'/Users/myuser/kds2/py2/venv38/lib/python3.8/site-packages',

Step 2. look for dependencies in the *dist-info/METADATA files

change to the site-packages directory you found above.

I am looking for who is using bleach rather than elasticsearch

cd /Users/myuser/kds2/py2/venv38/lib/python3.8/site-packages

find . -name METADATA -exec grep -H -i bleach {} \; | grep Requires-Dist

Note: although it's not necessary to worry about it here, characters like - or _ in the package name may affect how the grep should be written.

output:

./readme_renderer-24.0.dist-info/METADATA:Requires-Dist: bleach (>=2.1.0)

So, the readme_renderer is what is pulling in this dependency.

Note using find . -name METADATA -exec grep -H Requires-Dist {} \; | grep bleach i.e. interchanging the grep sequence between Requires-Dist and your searched-for package doesn't work as well, as, in my case, it showed a lot of bleachs own dependencies.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.