How do i search for a package in python?

As of December the 14th, 2020, the pip search functionality has been disabled :

$ pip search cast
ERROR: XMLRPC request failed [code: -32500]
RuntimeError: PyPI's XMLRPC API is currently disabled due to unmanageable load and will be deprecated in the near future. See https://status.python.org/ for more information.

Alternatives

Here's a little tool called pip_search I've just found that does a simple search but it does the job.

This is pip_search v0.0.6 output:

$ pip_search pulsemixer
----------------  -------------------------------------------------------------------------------
Name              Description

pulsemixer        pulsemixer - CLI and curses mixer for PulseAudio
pulsectl-asyncio  Asyncio frontend for the pulsectl Python bindings of libpulse
pulsectl          Python high-level interface and ctypes-based bindings for PulseAudio (libpulse)
----------------  -------------------------------------------------------------------------------

UPDATE

pip_search has been updated, each folder is a clickable (CTRL+click) URL for each project, now it looks like this:

$ pip_search pulsemixer
                                           🐍 https://pypi.org/search/?q=pulsemixer 🐍                                            
┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Package             ┃ Version ┃ Released     ┃ Description                                                                     ┃
┡━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ 📂 pulsemixer       │ 1.5.1   │ Apr 11, 2020 │ pulsemixer - CLI and curses mixer for PulseAudio                                │
│ 📂 pulsectl-asyncio │ 0.1.7   │ Jun 13, 2021 │ Asyncio frontend for the pulsectl Python bindings of libpulse                   │
│ 📂 pulsectl         │ 21.5.18 │ May 22, 2021 │ Python high-level interface and ctypes-based bindings for PulseAudio (libpulse) │
└─────────────────────┴─────────┴──────────────┴─────────────────────────────────────────────────────────────────────────────────┘

To install it, just type:

pip install pip_search


There's also another tool that I've just tried called pypisearch.

To install it, just type: pip install pypisearch

And it works like this:

$ python -m pypisearch pulsemixer
pulsemixer (1.5.1)        [installed 1.5.0] pulsemixer - CLI and curses mixer for PulseAudio
pulsectl-asyncio (0.1.5)  Asyncio frontend for the pulsectl Python bindings of libpulse
pulsectl (21.3.4)         Python high-level interface and ctypes-based bindings for PulseAudio (libpulse)

The Pip, Pipenv, Anaconda Navigator, and Conda Package Managers can all be used to list installed Python packages.

You can also use the ActiveState Platform’s command line interface (CLI), the State Tool to list all installed packages using a simple “state packages” command. For a complete list of all packages and dependencies  (including OS-level and transitive dependencies, as well as shared libraries), you can use the Web GUI, which provides a full Bill of Materials view. Give it a try by signing up for a free ActiveState Platform account.

Before getting a list of installed packages, it’s always a good practice to ensure that up-to-date versions of Python, Pip, Anaconda Navigator and Conda are in place.

List Installed Packages with Pip

Both  pip list  and  pip freeze  will generate a list of installed packages, just with differently formatted results. Keep in mind that  pip list  will list ALL installed packages (regardless of how they were installed). while  pip freeze  will list only everything installed by Pip.

For example:

pip list

Output:

Package                             Version
---------------------------------- ----------
absl-py                              0.7.0
pip freeze

Output:

absl-py==0.7.0

List Packages in a Console with Pip

To list all installed packages from a Python console using pip, you can utilize the following script:

>>> import pkg_resources
installed_packages = pkg_resources.working_set
installed_packages_list = sorted(["%s==%s" % (i.key, i.version)
   for i in installed_packages])
print(installed_packages_list)

Output:

['absl-py==0.7.0', 'adodbapi==2.6.0.7', 'alabaster==0.7.12', 'alembic==1.0.7', 'amqp==2.4.1', 'anyjson==0.3.3',

List Modules in a Console without Pip 

To list all installed modules from a python console without pip, you can use the following command:

>>> help("modules")

Note that there are some drawbacks to this approach, including:

  • If there are a lot of installed packages, this method can take a long time to import each module before it can search that module’s path for sub-modules.
  • Modules that have code outside of an if __name__ == “__main__”: code block, and if user input is expected, may cause the code to enter an infinite loop or hang.

List Installed Packages with Pipenv

The  pipenv lock -r command can be used to generate output from a pipfile.lock file in a pipenv environment. All packages, including dependencies will be listed in the output. For example:

pipenv lock -r

Output:

-i https://pypi.org/simple
certifi==2019.11.28
chardet==3.0.4
idna==2.9
requests==2.23.0
urllib3==1.25.8

List Installed Packages with Anaconda Navigator

To list installed packages in an Anaconda environment using Anaconda Navigator, do the following:

  • Start the Anaconda Navigator application.
  • Select Environments in the left column.
  • A dropdown box at the center-top of the GUI should list installed packages. If not, then select Installed in the dropdown menu to list all packages.

List Installed Packages with Conda

The conda list command can be used to list all packages in a conda environment:

conda list

Output:

# packages in environment at C:\Anaconda2_4.3.1:
#
_license                  1.1 py27_1
alabaster 0.7.9           py27_0

Globally vs Locally Installed Packages

For information about generating a list of installed packages globally vs locally, refer to: 

How to List Globally Installed Packages vs Locally Installed Packages in Python

List Installed Packages with the ActiveState Platform

To view a list of installed Python packages in your currently active project using the ActiveState Platform, run the following command on the command line:

state show packages

The output is a full list of installed packages in your current project:

matplotlib
numpy
pandas
scikit-learn
scipy

You can also obtain a complete software bill of materials view of all packages, dependencies, transitives dependencies (ie., dependencies of dependencies), OS-level dependencies and shared libraries (ie., OpenSSL) using the ActiveState Platform’s Web GUI:

How do i search for a package in python?

Where can I find Python packages?

When a package is installed globally, it's made available to all users that log into the system. Typically, that means Python and all packages will get installed to a directory under /usr/local/bin/ for a Unix-based system, or \Program Files\ for Windows.

How do I search for a specific module in Python?

How to Check if Python module is installed? You can use pip commands with grep command to search for any specific module installed on your system. For instance, you can also list out all installed modules with the suffix “re” in the module name.