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 tools (in this case apt-get on Debian).
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 tools (in this case apt-get on Debian).
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.
As @almenon pointed out, this no longer works and it is not the supported way to get package information in your code. The following raises an exception:
import pip
installed_packages = dict([(package.project_name, package.version)
for package in pip.get_installed_distributions()])
To accomplish this, you can import pkg_resources. Here's an example:
import pkg_resources
installed_packages = dict([(package.project_name, package.version)
for package in pkg_resources.working_set])
I'm on v3.6.5
pip freeze lists all installed packages even if not by pip/easy_install. On CentOs/Redhat a package installed through rpm is found.
If you use the Anaconda python distribution, you can use the conda list command to see what was installed by what method:
user@pc:~ $ conda list
# packages in environment at /anaconda3:
#
# Name Version Build Channel
_ipyw_jlab_nb_ext_conf 0.1.0 py36h2fc01ae_0
alabaster 0.7.10 py36h174008c_0
amqp 2.2.2 <pip>
anaconda 5.1.0 py36_2
anaconda-client 1.6.9 py36_0
To grab the entries installed by pip (including possibly pip itself):
user@pc:~ $ conda list | grep \<pip
amqp 2.2.2 <pip>
astroid 1.6.2 <pip>
billiard 3.5.0.3 <pip>
blinker 1.4 <pip>
ez-setup 0.9 <pip>
feedgenerator 1.9 <pip>
Of course you probably want to just select the first column, which you can do with (excluding pip if needed):
user@pc:~ $ conda list | awk '$3 ~ /pip/ {if ($1 != "pip") print $1}'
amqp
astroid
billiard
blinker
ez-setup
feedgenerator
Finally you can grab these values and pip uninstall all of them using the following:
user@pc:~ $ conda list | awk '$3 ~ /pip/ {if ($1 != "pip") print $1}' | xargs pip uninstall -y
Note the use of the -y flag for the pip uninstall to avoid having to give confirmation to delete.
For those who don't have pip installed, I found this quick script on github (works with Python 2.7.13):
import pkg_resources
distros = pkg_resources.AvailableDistributions()
for key in distros:
print distros[key]