Find all packages installed with easy_install/pip?

前端 未结 18 1085
醉话见心
醉话见心 2020-11-27 08:47

Is there a way to find all Python PyPI packages that were installed with easy_install or pip? I mean, excluding everything that was/is installed with the distributions tool

相关标签:
18条回答
  • 2020-11-27 09:39

    Adding to @Paul Woolcock's answer,

    pip freeze > requirements.txt
    

    will create a requirements file with all installed packages along with the installed version numbers in the active environment at the current location. Running

    pip install -r requirements.txt
    

    will install the packages specified in the requirements file.

    0 讨论(0)
  • 2020-11-27 09:39

    pip freeze lists all installed packages even if not by pip/easy_install. On CentOs/Redhat a package installed through rpm is found.

    0 讨论(0)
  • 2020-11-27 09:40

    If Debian behaves like recent Ubuntu versions regarding pip install default target, it's dead easy: it installs to /usr/local/lib/ instead of /usr/lib (apt default target). Check https://askubuntu.com/questions/173323/how-do-i-detect-and-remove-python-packages-installed-via-pip/259747#259747

    I am an ArchLinux user and as I experimented with pip I met this same problem. Here's how I solved it in Arch.

    find /usr/lib/python2.7/site-packages -maxdepth 2 -name __init__.py | xargs pacman -Qo | grep 'No package'
    

    Key here is /usr/lib/python2.7/site-packages, which is the directory pip installs to, YMMV. pacman -Qo is how Arch's pac kage man ager checks for ownership of the file. No package is part of the return it gives when no package owns the file: error: No package owns $FILENAME. Tricky workaround: I'm querying about __init__.py because pacman -Qo is a little bit ignorant when it comes to directories :(

    In order to do it for other distros, you have to find out where pip installs stuff (just sudo pip install something), how to query ownership of a file (Debian/Ubuntu method is dpkg -S) and what is the "no package owns that path" return (Debian/Ubuntu is no path found matching pattern). Debian/Ubuntu users, beware: dpkg -S will fail if you give it a symbolic link. Just resolve it first by using realpath. Like this:

    find /usr/local/lib/python2.7/dist-packages -maxdepth 2 -name __init__.py | xargs realpath | xargs dpkg -S 2>&1 | grep 'no path found'
    

    Fedora users can try (thanks @eddygeek):

    find /usr/lib/python2.7/site-packages -maxdepth 2 -name __init__.py | xargs rpm -qf | grep 'not owned by any package'
    
    0 讨论(0)
  • 2020-11-27 09:40

    Take note that if you have multiple versions of Python installed on your computer, you may have a few versions of pip associated with each.

    Depending on your associations, you might need to be very cautious of what pip command you use:

    pip3 list 
    

    Worked for me, where I'm running Python3.4. Simply using pip list returned the error The program 'pip' is currently not installed. You can install it by typing: sudo apt-get install python-pip.

    0 讨论(0)
  • 2020-11-27 09:40

    Here is the one-liner for fedora or other rpm distros (based on @barraponto tips):

    find /usr/lib/python2.7/site-packages -maxdepth 2 -name __init__.py | xargs rpm -qf | grep 'not owned by any package'
    

    Append this to the previous command to get cleaner output:

     | sed -r 's:.*/(\w+)/__.*:\1:'
    
    0 讨论(0)
  • 2020-11-27 09:41

    As of version 1.3 of pip you can now use pip list

    It has some useful options including the ability to show outdated packages. Here's the documentation: https://pip.pypa.io/en/latest/reference/pip_list/

    0 讨论(0)
提交回复
热议问题