SilentDev
SilentDev

Reputation: 22747

Where does pip install its packages?

I activated a virtualenv which has pip installed. I did

pip3 install Django==1.8

and Django successfully downloaded. Now, I want to open up the Django folder. Where is the folder located?

Normally it would be in "downloads", but I'm not sure where it would be if I installed it using pip in a virtualenv.

Upvotes: 816

Views: 1340998

Answers (12)

user1556435
user1556435

Reputation: 1056

Not a direct recommendation to run this (because I doubt this behaviour is stable across versions of pip), but the most comprehensive overview of installed files I got from piping n into pip uninstall ... (i.e request to uninstall, but then 'no' to proceed).

$ echo n | python3 -m pip uninstall patchelf
Uninstalling patchelf-0.17.2.1:
  /usr/local/bin/patchelf
  /usr/local/lib64/python3.6/site-packages/patchelf-0.17.2.1.dist-info/COPYING
  /usr/local/lib64/python3.6/site-packages/patchelf-0.17.2.1.dist-info/INSTALLER
  /usr/local/lib64/python3.6/site-packages/patchelf-0.17.2.1.dist-info/LICENSE
  /usr/local/lib64/python3.6/site-packages/patchelf-0.17.2.1.dist-info/METADATA
  /usr/local/lib64/python3.6/site-packages/patchelf-0.17.2.1.dist-info/RECORD
  /usr/local/lib64/python3.6/site-packages/patchelf-0.17.2.1.dist-info/WHEEL
  /usr/local/lib64/python3.6/site-packages/patchelf-0.17.2.1.dist-info/top_level.txt
Proceed (y/n)?

Upvotes: 0

Ram Ghadiyaram
Ram Ghadiyaram

Reputation: 29145

pip list -v will give

beyond this python program like this worked for me as well. just giving as alternative solution

import subprocess

installed_packages = subprocess.check_output(['pip', 'list', '--format=freeze']).decode().split('\
')

print("Installed packages and their locations:")
print("=======================================")

for package in installed_packages:
    if package:
        package_name = package.split('==')[0]
        try:
            package_info = subprocess.check_output(['pip', 'show', package_name]).decode().split('\
')
            for line in package_info:
if line.startswith('Name:') or line.startswith('Location:'):
                    print(line)
        except subprocess.CalledProcessError as e:
            print(f"Error: Could not find package {package_name}")

print("=======================================")

Result :

Installed packages and their locations:
=======================================
Name: boto3
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: botocore
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: build
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: CacheControl
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: certifi
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: charset-normalizer
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: cleo
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: colorama
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: crashtest
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: distlib
Location: c:\users\ramgh\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: dulwich
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: fastjsonschema
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: filelock
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: idna
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: importlib_metadata
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: importlib_resources
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: installer
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: jaraco.classes
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: jmespath
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: keyring
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: more-itertools
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: msgpack
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: numpy
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: packaging
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: pandas
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: pexpect
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: pip
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: pkginfo
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: platformdirs
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: poetry
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: poetry-core
Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
Name: poetry-plugin-export
 Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
 Name: ptyprocess
 Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
 Name: py4j
 Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
 Name: pyproject-hooks
 Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
 Name: pyspark
 Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
 Name: python-dateutil
 Location: c:\users\ramgh\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
 Name: pytz
 Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
 Name: pywin32-ctypes
 Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
 Name: rapidfuzz
 Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
 Name: requests
 Location: c:\users\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages
 Name: requests-toolbelt
 Location: c:\

Upvotes: 1

rofrol
rofrol

Reputation: 15216

% python -c "import sysconfig; print(sysconfig.get_path('purelib'))"
/opt/homebrew/lib/python3.11/site-packages
% pip show yt-dlp
Name: yt-dlp
Version: 2023.3.4
Summary: A youtube-dl fork with additional features and patches
Home-page: https://github.com/yt-dlp/yt-dlp
Author:
Author-email:
License:
Location: /opt/homebrew/lib/python3.11/site-packages
Requires: brotli, certifi, mutagen, pycryptodomex, websockets
Required-by:

How do I find the location of my Python site-packages directory?

or shorter python -m pip show pip

Where does pip install its packages?

Upvotes: 9

Avinash Kumar Ranjan
Avinash Kumar Ranjan

Reputation: 414

If you have installed packages via pip and are running the code on Windows, the package should be located in one of the following directories:

User Site Packages: C:\Users\USERNAME\AppData\Roaming\Python\PythonXX\site-packages
Global Site Packages: C:\Program Files\PythonXX\Lib\site-packages
Note that "USERNAME" and "XX" will depend on your system configuration and the version of Python you are using. Also, if you have installed Python in a different location than the default, the paths may differ.

If you're not sure where the package is installed, you can open a command prompt and type pip show 'package-name'. This will show you the installation location of the package.

Upvotes: 1

wisbucky
wisbucky

Reputation: 37797

The safest way is to call pip through the specific python that you are executing. If you run pip show pip directly, it may be calling a different pip than the one that python is calling. Examples:

$ python -m pip show pip
$ python3 -m pip show pip
$ /usr/bin/python -m pip show pip
$ /usr/local/bin/python3 -m pip show pip

Here's an example showing how they can differ:

$ pip show pip

Location: /usr/local/lib/python3.9/site-packages

$ python -m pip show pip

Location: /Library/Python/2.7/site-packages

Upvotes: 34

Gael Lorieul
Gael Lorieul

Reputation: 3246

One can import the package then consult its help

import statsmodels
help(sm)

At the very bottom of the help there is a section FILE that indicates where this package was installed.

This solution was tested with at least matplotlib (3.1.2) and statsmodels (0.11.1) (python 3.8.2).

Upvotes: 13

Ryan
Ryan

Reputation: 769

Easiest way is probably

pip3 -V

This will show you where your pip is installed and therefore where your packages are located.

Upvotes: 66

flow2k
flow2k

Reputation: 4347

In a Python interpreter or script, you can do

import site
site.getsitepackages() # List of global package locations

and

site.getusersitepackages() # String for user-specific package location

For locations third-party packages (those not in the core Python distribution) are installed to.

On my Homebrew-installed Python on macOS, the former outputs

['/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages'],

which canonicalizes to the same path output by pip show, as mentioned in a previous answer:

$ readlink -f /usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages
/usr/local/lib/python3.7/site-packages

Reference: https://docs.python.org/3/library/site.html#site.getsitepackages

Upvotes: 28

jiasli
jiasli

Reputation: 9128

pip list -v can be used to list packages' install locations, introduced in https://pip.pypa.io/en/stable/news/#b1-2018-03-31

Show install locations when list command ran with “-v” option. (#979)

>pip list -v
Package                  Version   Location                                                             Installer
------------------------ --------- -------------------------------------------------------------------- ---------
alabaster                0.7.12    c:\users\me\appdata\local\programs\python\python38\lib\site-packages pip
apipkg                   1.5       c:\users\me\appdata\local\programs\python\python38\lib\site-packages pip
argcomplete              1.10.3    c:\users\me\appdata\local\programs\python\python38\lib\site-packages pip
astroid                  2.3.3     c:\users\me\appdata\local\programs\python\python38\lib\site-packages pip
...

This feature is introduced in pip 10.0.0b1. On Ubuntu 18.04 (Bionic Beaver), pip or pip3 installed with sudo apt install python-pip or sudo apt install python3-pip is 9.0.1 which doesn't have this feature.

Check https://github.com/pypa/pip/issues/5599 for suitable ways of upgrading pip or pip3.

Upvotes: 235

gdbj
gdbj

Reputation: 17485

pip show <package name> will provide the location for Windows and macOS, and I'm guessing any system. :)

For example:

> pip show cvxopt
Name: cvxopt
Version: 1.2.0
...
Location: /usr/local/lib/python2.7/site-packages

Upvotes: 1216

khampson
khampson

Reputation: 15296

pip when used with virtualenv will generally install packages in the path <virtualenv_name>/lib/<python_ver>/site-packages.

For example, I created a test virtualenv named venv_test with Python 2.7, and the django folder is in venv_test/lib/python2.7/site-packages/django.

Upvotes: 182

CognizantApe
CognizantApe

Reputation: 1179

By default, on Linux, Pip installs packages to /usr/local/lib/python2.7/dist-packages.

Using virtualenv or --user during install will change this default location. If you use pip show make sure you are using the right user or else pip may not see the packages you are referencing.

Upvotes: 25

Related Questions