How to List Python Packages – Globally Installed vs Locally Installed

listing 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.

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:

pip list

or

pip freeze

To list a single globally installed package and its version #, use the following command depending on your OS:

Linux:

pip freeze | grep <packagename>

Windows:

pip freeze | findstr <packagename>

How to List Python Packages that are Locally Installed

Pip

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

or

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:

Linux:

pip freeze --user | grep <packagename> 

Windows:

pip freeze --user | findstr <packagename>

Pipenv

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.

ActiveState Platform

If you prefer to see a visual representation of the packages in your local/virtual environment, you can use the ActiveState Platform’s Web GUI, which shows:

  • Installed top-level packages
  • Installed package dependencies
  • Installed shared (i.e., OS-level) dependencies

BOMcomplete

 

 

 

 

 

Conda

To list locally installed packages and their version # within a Conda environment, open the Anaconda Prompt and enter the following command:

conda list

Anaconda Navigator

To list all installed packages in a local Anaconda environment using Anaconda Navigator, do the following:

  1. Start the Anaconda Navigator application.
  2. Select Environments in the left-hand column.
  3. 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())'

or 

>>> 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

The ActiveState Platform automatically builds all Python packages including linked C libraries from source code, and packages them for Windows, Linux and macOS. Because it does it all server-side, there’s no need to maintain local build environments.

Try it out by signing up for a free ActiveState Platform account.

Related Links

Recent Posts

Tech Debt Best Practices: Minimizing Opportunity Cost & Security Risk

Tech debt is an unavoidable consequence of modern application development, leading to security and performance concerns as older open-source codebases become more vulnerable and outdated. Unfortunately, the opportunity cost of an upgrade often means organizations are left to manage growing risk the best they can. But it doesn’t have to be this way.

Read More
Scroll to Top