How to List Python Packages – Globally Installed vs Locally Installed
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.
Conversely, when a package is installed locally, it’s only made available to the user that installed it. Locally installed Python and all packages will be installed under a directory similar to ~/.local/bin/ for a Unix-based system, or \Users\Username\AppData\Local\Programs\ for Windows.
How to List Python Packages
As a best practice, you should always install Python and the packages you need into a separate virtual environment for each project. This creates an isolated environment that will avoid many of the problems that arise because of shared libraries/ dependencies.
The Pip Package Manager can be used to list both globally and locally installed Python packages. The Pipenv, Anaconda Navigator and Conda package managers can also be used to list locally installed packages in their respective environments.
Before listing packages, it’s always a good practice to ensure that up-to-date versions of Python, Pip, Pipenv, Anaconda Navigator and Conda are in place.
How to List Python Packages that are Globally Installed
Pip installs packages globally by default. To list globally installed packages and their version # use:
To list a single globally installed package and its version #, use the following command depending on your OS:
pip freeze | grep <packagename>
pip freeze | findstr <packagename>
How to List Python Packages that are Locally Installed
Although pip installs packages globally by default, packages that have been installed locally with the –user option can also be listed using the same –user option, as follows:
pip list --user
pip freeze --user
If you just want to list a single, locally installed package and its version #, you can use one of the following commands, depending on your OS:
pip freeze --user | grep <packagename>
pip freeze --user | findstr <packagename>
To list locally installed packages and their version # within a pipenv environment, cd into a pipenv project and enter the following command:
pipenv lock -r
This command will list all packages installed, including any dependencies that are found in a Pipfile.lock file.
To list locally installed packages and their version # within a Conda environment, open the Anaconda Prompt and enter the following command:
To list all installed packages in a local Anaconda environment using Anaconda Navigator, do the following:
- Start the Anaconda Navigator application.
- Select Environments in the left-hand column.
- A dropdown box at the center-top of the GUI should list installed packages. If not, then select Installed from the dropdown menu to list the packages.
How to Determine the Location of Globally Installed Packages
As noted earlier, globally installed Python packages can typically be found in the default install location for your OS. However, it is possible to install packages into a non-default directory. In order to determine where global packages have been installed, use the following command:
python -m site
To show the location of globally installed packages in a python console, use the following script:
>>> import site >>> print(site.getsitepackages())'
>>> import sys >>> sys.path
Using Pip Show for Package Location
The pip show command can provide information about a single, globally installed package, including its location:
pip show <packagename>
How to Determine the Location of Locally Installed Packages
To list the location of locally installed packages, use the following command:
python -m site --user-site