[python] 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.

This question is related to python django pip virtualenv

The answer is


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

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.


Easiest way is probably

pip3 -V

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


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.


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


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


Questions with python tag:

programming a servo thru a barometer Is there a way to view two blocks of code from the same file simultaneously in Sublime Text? python variable NameError Why my regexp for hyphenated words doesn't work? Comparing a variable with a string python not working when redirecting from bash script is it possible to add colors to python output? Get Public URL for File - Google Cloud Storage - App Engine (Python) Real time face detection OpenCV, Python xlrd.biffh.XLRDError: Excel xlsx file; not supported Could not load dynamic library 'cudart64_101.dll' on tensorflow CPU-only installation Upgrade to python 3.8 using conda Unable to allocate array with shape and data type How to fix error "ERROR: Command errored out with exit status 1: python." when trying to install django-heroku using pip How to prevent Google Colab from disconnecting? "UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure." when plotting figure with pyplot on Pycharm How to fix 'Object arrays cannot be loaded when allow_pickle=False' for imdb.load_data() function? "E: Unable to locate package python-pip" on Ubuntu 18.04 Tensorflow 2.0 - AttributeError: module 'tensorflow' has no attribute 'Session' Jupyter Notebook not saving: '_xsrf' argument missing from post How to Install pip for python 3.7 on Ubuntu 18? Python: 'ModuleNotFoundError' when trying to import module from imported package OpenCV TypeError: Expected cv::UMat for argument 'src' - What is this? Requests (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.") Error in PyCharm requesting website How to setup virtual environment for Python in VS Code? Pylint "unresolved import" error in Visual Studio Code Pandas Merging 101 Numpy, multiply array with scalar What is the meaning of "Failed building wheel for X" in pip install? Selenium: WebDriverException:Chrome failed to start: crashed as google-chrome is no longer running so ChromeDriver is assuming that Chrome has crashed Could not install packages due to an EnvironmentError: [Errno 13] OpenCV !_src.empty() in function 'cvtColor' error ConvergenceWarning: Liblinear failed to converge, increase the number of iterations How to downgrade python from 3.7 to 3.6 I can't install pyaudio on Windows? How to solve "error: Microsoft Visual C++ 14.0 is required."? Iterating over arrays in Python 3 How do I install opencv using pip? How do I install Python packages in Google's Colab? How do I use TensorFlow GPU? How to upgrade Python version to 3.7? How to resolve TypeError: can only concatenate str (not "int") to str How can I install a previous version of Python 3 in macOS using homebrew? Flask at first run: Do not use the development server in a production environment TypeError: only integer scalar arrays can be converted to a scalar index with 1D numpy indices array What is the difference between Jupyter Notebook and JupyterLab? Pytesseract : "TesseractNotFound Error: tesseract is not installed or it's not in your path", how do I fix this? Could not install packages due to a "Environment error :[error 13]: permission denied : 'usr/local/bin/f2py'" How do I resolve a TesseractNotFoundError? Trying to merge 2 dataframes but get ValueError Authentication plugin 'caching_sha2_password' is not supported Python Pandas User Warning: Sorting because non-concatenation axis is not aligned

Questions with django tag:

How to fix error "ERROR: Command errored out with exit status 1: python." when trying to install django-heroku using pip Pylint "unresolved import" error in Visual Studio Code Is it better to use path() or url() in urls.py for django 2.0? Unable to import path from django.urls Error loading MySQLdb Module 'Did you install mysqlclient or MySQL-python?' ImportError: Couldn't import Django Django - Reverse for '' not found. '' is not a valid view function or pattern name Class has no objects member Getting TypeError: __init__() missing 1 required positional argument: 'on_delete' when trying to add parent table after child table with entries How to switch Python versions in Terminal? ImportError: No module named 'django.core.urlresolvers' How to set environment variables in PyCharm? How to get Django and ReactJS to work together? Invalid http_host header Django model "doesn't declare an explicit app_label" "Post Image data using POSTMAN" TypeError: int() argument must be a string, a bytes-like object or a number, not 'list' Django URLs TypeError: view must be a callable or a list/tuple in the case of include() What is a NoReverseMatch error, and how do I fix it? What does on_delete do on Django models? Django values_list vs values Django download a file Uncaught TypeError: $(...).datepicker is not a function(anonymous function) Django - makemigrations - No changes detected How can I enable CORS on Django REST Framework Django - Did you forget to register or load this tag? Django upgrading to 1.9 error "AppRegistryNotReady: Apps aren't loaded yet." Django Rest Framework -- no module named rest_framework How to revert the last migration? What's the difference between select_related and prefetch_related in Django ORM? Django: save() vs update() to update the database? Where does pip install its packages? no module named urllib.parse (How should I install it?) How to set the timezone in Django? You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application Django Model() vs Model.objects.create() NumPy array is not JSON serializable React Error: Target Container is not a DOM Element OperationalError, no such column. Django how to use python2.7 pip instead of default pip The view didn't return an HttpResponse object. It returned None instead You are trying to add a non-nullable field 'new_field' to userprofile without a default ImproperlyConfigured: You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings 'NOT NULL constraint failed' after adding to models.py Django 1.7 - "No migrations to apply" when run migrate after makemigrations How to compare two JSON objects with the same elements in a different order equal? Django: OperationalError No Such Table Embed YouTube video - Refused to display in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN' Django 1.7 throws django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet Mac OS X - EnvironmentError: mysql_config not found

Questions with pip tag:

How to fix error "ERROR: Command errored out with exit status 1: python." when trying to install django-heroku using pip "E: Unable to locate package python-pip" on Ubuntu 18.04 How to Install pip for python 3.7 on Ubuntu 18? What is the meaning of "Failed building wheel for X" in pip install? Could not install packages due to an EnvironmentError: [Errno 13] How do I install Python packages in Google's Colab? Conda version pip install -r requirements.txt --target ./lib pip: no module named _internal AttributeError: Module Pip has no attribute 'main' Error after upgrading pip: cannot import name 'main' Not able to install Python packages [SSL: TLSV1_ALERT_PROTOCOL_VERSION] 'pip install' fails for every package ("Could not find a version that satisfies the requirement") Could not find a version that satisfies the requirement tensorflow pip install returning invalid syntax How to update/upgrade a package using pip? Pipenv: Command Not Found pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available "Could not find a version that satisfies the requirement opencv-python" How to start Spyder IDE on Windows Python: How to pip install opencv2 with specific version 2.4.9? How to install PIP on Python 3.6? What is the purpose of "pip install --user ..."? How to install pandas from pip on windows cmd? How to install pip for Python 3.6 on Ubuntu 16.10? "SSL certificate verify failed" using pip to install packages ImportError: No module named tensorflow python pip on Windows - command 'cl.exe' failed How to install pip3 on Windows? "pip install json" fails on Ubuntu How to use requirements.txt to install all dependencies in a python project "ssl module in Python is not available" when installing package with pip3 Using Pip to install packages to Anaconda Environment Checking whether the pip is installed? pip or pip3 to install packages for Python 3? pip not working in Python Installation in Windows 10 How to add a custom CA Root certificate to the CA Store used by pip in Windows? TensorFlow not found using pip Conda uninstall one package and one package only How to install Openpyxl with pip python mpl_toolkits installation issue Python PIP Install throws TypeError: unsupported operand type(s) for -=: 'Retry' and 'int' Pip - Fatal error in launcher: Unable to create process using '"' Pip "Could not find a that satisfies the requirement" How do I install a pip package globally instead of locally? installing python packages without internet and using source code as .tar.gz and .whl Install pip in docker pip install - locale.Error: unsupported locale setting "pip install unroll": "python setup.py egg_info" failed with error code 1 pip installs packages successfully, but executables not found from command line Pip install - Python 2.7 - Windows 7

Questions with virtualenv tag:

How to setup virtual environment for Python in VS Code? Conda version pip install -r requirements.txt --target ./lib What is the purpose of "pip install --user ..."? What is the difference between venv, pyvenv, pyenv, virtualenv, virtualenvwrapper, pipenv, etc? ImportError: No module named 'encodings' how to specify new environment location for conda create Use virtualenv with Python with Visual Studio Code in Ubuntu Is it ok having both Anacondas 2.7 and 3.5 installed in the same time? How to uninstall a package installed with pip install --user Unable to install boto3 Virtualenv Command Not Found How to run Spyder in virtual environment? Where does pip install its packages? Using (Ana)conda within PyCharm Using Python 3 in virtualenv Broken references in Virtualenvs How do I activate a virtualenv inside PyCharm's terminal? How to install a package inside virtualenv? error: could not create '/usr/local/lib/python2.7/dist-packages/virtualenv_support': Permission denied pip installing in global site-packages instead of virtualenv How to activate an Anaconda environment Python: No acceptable C compiler found in $PATH when installing python ImportError: No module named Crypto.Cipher How to avoid "Permission denied" when using pip with virtualenv How can I make a list of installed packages in a certain virtualenv? How do I update pip itself from inside my virtual environment? How to activate virtualenv? How to install a specific version of a package with pip? bash: mkvirtualenv: command not found How to source virtualenv activate in a Bash script Where is virtualenvwrapper.sh after pip install? Make virtualenv inherit specific packages from your global site-packages How do I tell a Python script to use a particular version Upgrade python in a virtualenv Pip install Matplotlib error with virtualenv setting an environment variable in virtualenv Issue with virtualenv - cannot activate No module named pkg_resources How can I install packages using pip according to the requirements.txt file from a local directory? List all virtualenv Activate a virtualenv with a Python script Is it bad to have my virtualenv directory inside my git repository? no module named zlib Comprehensive beginner's virtualenv tutorial? What is the official "preferred" way to install pip and virtualenv systemwide? Is it possible to install another version of Python to Virtualenv? How to install psycopg2 with "pip" on Python? How do you set your pythonpath in an already-created virtualenv? How can I upgrade specific packages using pip and a requirements file? Python virtualenv questions