How do I find the location of my site-packages directory?
Join Stack Overflow to learn, share knowledge, and build your career.
|
There are two types of site-packages directories, global and per user.
|
|||||
|
|
I had to do something slightly different for a project I was working on: find the relative site-packages directory relative to the base install prefix. If the site-packages folder was in Similar to cheater's answer, my solution peeks deep into the guts of Distutils, to find the path that actually gets passed around inside
That should print something like |
|||
|
|
|
This should work on all distributions in and out of virtual environment due to it's "low-tech" nature. The os module always resides in the parent directory of 'site-packages'
To change dir to the site-packages dir I use the following alias (on *nix systems):
|
||||
|
|
|
Answer to old question. But use ipython for this.
This will give the following output about imaplib package -
|
|||||
|
(or just first item with |
|||||||||||||||||||||
|
|
The native system packages installed with python installation can be found at :
by using this small code :
However, the list of packages installed via
Or one can simply write the following command to list all paths where python packages are.
|
|||||
|
|
This is what worked for me:
|
|||||||||||||||||||||
|
|
Let's say you have installed the package 'django'. import it and type in dir(django). It will show you, all the functions and attributes with that module. Type in the python interpreter -
You can do the same thing if you have installed mercurial. This is for Snow Leopard. But I think it should work in general as well. |
||||
|
This works for me. It will get you both dist-packages and site-packages folders. If the folder is not on Python's path, it won't be doing you much good anyway.
Output (Ubuntu installation):
|
|||||||||||||||||
|
|
All the answers (or: the same answer repeated over and over) are inadequate. What you want to do is this:
The final line shows you the installation dir. Works on Ubuntu, whereas the above ones don't. Don't ask me about windows or other dists, but since it's the exact same dir that easy_install uses by default, it's probably correct everywhere where easy_install works (so, everywhere, even macs). Have fun. Note: original code has many swearwords in it. |
|||||||||||||
|
|
From "How to Install Django" documentation (though this is useful to more than just Django installation) - execute the following from the shell:
Formatted for readability (rather than use as a one-liner), that looks like the following:
|
|||||||||||||||||||||
|
|
For Ubuntu,
...is not correct. It will point you to This folder only contains packages your operating system has automatically installed for programs to run. On ubuntu, the site-packages folder that contains packages installed via setup_tools\easy_install\pip will be in The second folder is probably the more useful one if the use case is related to installation or reading source code. If you do not use Ubuntu, you are probably safe copy-pasting the first code box into the terminal. |
|||||||||||||
|
|
A side-note: The proposed solution (distutils.sysconfig.get_python_lib()) does not work when there is more than one site-packages directory (as recommended by this article). It will only return the main site-packages directory. Alas, I have no better solution either. Python doesn't seem to keep track of site-packages directories, just the packages within them. |
|||||||||||||
|
|
An additional note to the |
|||
|
|
|
As others have noted,
...though the default
(it also adds That said, what's the context? You shouldn't be messing with your |
|||||||||||||
|
|
|||
|
|
pip show <package name>– joshuakcockrell Jul 25 '17 at 5:18