Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing " get_installed_distributions() " attribute in module " pip " #5243

Closed
realJustinLee opened this issue Apr 15, 2018 · 13 comments
Closed
Labels
auto-locked Outdated issues that have been locked by automation C: public api Public API stuff type: support User Support

Comments

@realJustinLee
Copy link

  • Pip version: 10.0.0
  • Python version: 3.6.5 && 2.7.14
  • Operating system: macOS 10.13.5

Description:

for dist in pip.get_installed_distributions():
AttributeError: 'module' object has no attribute 'get_installed_distributions'

What I've run:

pip.get_installed_distributions()
@pfmoore
Copy link
Member

pfmoore commented Apr 15, 2018

See https://pip.pypa.io/en/latest/user_guide/#using-pip-from-your-program - importing functions from pip is not supported. In this case, setuptools (specifically pkg_resources) probably has the functionality you need.

@codingCoffee

This comment has been minimized.

@pfmoore
Copy link
Member

pfmoore commented Apr 15, 2018

@codingCoffee No, that's explicitly not the right thing to do. Please don't do this, we will not support such usage.

@codingCoffee
Copy link

codingCoffee commented Apr 16, 2018

@pfmoore, I agree, that it's a bad practice. I just meant the comment as a quick fix to the problem

@RonnyPfannschmidt
Copy link
Contributor

@08zhangyi thats horrible - pip has json output for that which gives correct parsed results, please edit/remove the bad code

@codingCoffee same for your bad example - because people do actually use bad examples because they are the first thing they find that works

@pradyunsg
Copy link
Member

Hi @Great-Li-Xin!

You can use pkg_resources.working_set for getting the same information. It's part of setuptools, which is probably already installed on your system. That is a supported way for getting the exact same information. Using pip's internal functions is not supported.

import pkg_resources

dists = [d for d in pkg_resources.working_set]
# Filter out distributions you don't care about and use.

The function @codingCoffee mentioned has moved into an pip._internal name, to signify that usage of the same is not supported and may change anytime without notice. It is strongly discouraged to use it.

@08zhangyi that seems to be a very fragile way to do this. As @RonnyPfannschmidt points out, there's JSON output pip list --format=json that is much better suited for consumption by computers.


@Great-Li-Xin feel free to close this issue if your concerns are addressed. :)

@08zhangyi
Copy link

@pradyunsg , thank you! I have deleted my answer and changed my code as you say.

@pradyunsg pradyunsg added C: public api Public API stuff type: support User Support S: awaiting response Waiting for a response/more information labels Apr 16, 2018
@dstufft dstufft closed this as completed Apr 17, 2018
bear80 added a commit to bear80/plugins that referenced this issue Apr 24, 2018
From pip 10.0.0 on pip.get_installed_distributions does not work any more. I suggest to use pkg_resources.working_set instead as discussed here: pypa/pip#5243. Works fine for me...
tannart added a commit to tannart/safety that referenced this issue May 2, 2018
As discussed in this thread: pypa/pip#5243
use of the functions inside pip._internal is strongly discouraged. As
such I have replaced this functions usage with the pip maintainers
recommended solution.
@WonderMr

This comment has been minimized.

@pradyunsg pradyunsg removed the S: awaiting response Waiting for a response/more information label May 25, 2018
@pradyunsg
Copy link
Member

For pip 10 use from pip._internal.utils.misc import get_installed_distributions

To restate, this function has moved into pip._internal namespace, to signify that usage of the same is not supported and may change anytime without notice. It is strongly discouraged to use it.

@Yemsheng
Copy link

Yemsheng commented Jun 7, 2018

Downgrade pip to 9.0.3 will fix this problem

pip install pip==9.0.3

@pradyunsg
Copy link
Member

@Yemsheng Downgrading to pip 9.0.3 is a way to work around this issue; you're essentially pinning yourself to an older version of pip until the underlying project changes itself to use a supported way to perform these actions.

dune-community-bot pushed a commit to dune-mirrors/dune-common that referenced this issue Jun 30, 2018
pip 10 moved several interfaces to an internal package, causing our pyversion.py script to fail.
This patches fixes the issue by getting installed distributions directly from setuptools, as
suggested in pypa/pip#5243.

See merge request core/dune-common!540

(cherry picked from commit 746aa62)

2443bc4 Make Python package detection work with pip 10
cmumford added a commit to starryexpanse/continuous-build that referenced this issue Jul 21, 2018
KhasMek added a commit to KhasMek/datasploit that referenced this issue Jul 29, 2018
  pip.get_installed_distributions() is in internal function
  that was never meant to be externally called and has since
  been locked out by external functions.

  Lets switch over to the supported function in setuptools
  pkg_resources.get_distribution() to search the installed
  packages.

  See: pypa/pip#5243
  Fixes: 255
KhasMek added a commit to KhasMek/datasploit that referenced this issue Jul 29, 2018
  pip.get_installed_distributions() is in internal function
  that was never meant to be externally called and has since
  been locked out by external functions.

  Lets switch over to the supported function in setuptools
  pkg_resources.get_distribution() to search the installed
  packages.

  See: pypa/pip#5243
  Fixes: DataSploit#255
@kobigi
Copy link

kobigi commented Oct 20, 2018

well i believe the suggested solution is best for me
So i can remove the tight couple with pip

import pkg_resources

dists = [d for d in pkg_resources.working_set]

KhasMek added a commit to KhasMek/datasploit that referenced this issue Nov 14, 2018
  pip.get_installed_distributions() is in internal function
  that was never meant to be externally called and has since
  been locked out by external functions.

  Lets switch over to the supported function in setuptools
  pkg_resources.get_distribution() to search the installed
  packages.

  See: pypa/pip#5243
  Fixes: DataSploit#255
legalsylvain added a commit to legalsylvain/pywebdriver that referenced this issue Mar 18, 2019
@lock
Copy link

lock bot commented May 31, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot added the auto-locked Outdated issues that have been locked by automation label May 31, 2019
@lock lock bot locked as resolved and limited conversation to collaborators May 31, 2019
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
auto-locked Outdated issues that have been locked by automation C: public api Public API stuff type: support User Support
Projects
None yet
Development

No branches or pull requests

10 participants