103

After installing a package in an anaconda environment, I'll like to make some changes to the code in that package.

Where can I find the site-packages directory containing the installed packages? I do not find a directory /Users/username/anaconda/lib/python2.7/site-packages

Nyxynyx
  • 56,949
  • 141
  • 437
  • 770

10 Answers10

111

You can import the module and check the module.__file__ string. It contains the path to the associated source file.

Alternatively, you can read the File tag in the the module documentation, which can be accessed using help(module), or module? in IPython.

Arcturus B
  • 4,431
  • 4
  • 28
  • 47
  • 2
    My problem is that I get a package import "not found" error for the package that conda supposedly installed. So I would like to check where conda thinks that it installed the package. – Ben Farmer Nov 29 '19 at 13:09
  • @BenFarmer: this sounds like a rather different problem. Have you tried searching for something along the line of "conda list installed package paths"? This returns https://stackoverflow.com/q/46767012 and https://stackoverflow.com/q/47138241. – Arcturus B Nov 29 '19 at 13:31
  • 2
    thanks @Arcturus B just adding one example ```example: >>import tensorflow >>tensorflow.__file__``` – BrB Apr 09 '20 at 17:31
  • my problem is that I see it in conda list but I can't find where it would be located...any ideas? – Charlie Parker Sep 24 '20 at 18:19
78

Run this inside python shell:

from distutils.sysconfig import get_python_lib
print(get_python_lib())
Vlad Costin
  • 975
  • 7
  • 11
12

Linux users can find the locations of all the installed packages like this:

pip list | xargs -exec pip show

Updated 2022-03-21 to remove the unwanted table heading at the top of pip list output:

pip list | tail -n +3 | xargs -exec pip show
Steve
  • 1,116
  • 8
  • 24
  • Here is some elegant use of `xargs`! – ivan-k Apr 28 '16 at 16:56
  • i just used: pip show . It worked, I got the files. – numbers3567 Jul 27 '20 at 13:28
  • but he said he is using conda...? – Charlie Parker Sep 24 '20 at 18:16
  • my problem is that I see it in conda list but I can't find where it would be located...any ideas? – Charlie Parker Sep 24 '20 at 18:19
  • @CharlieParker it sounds like you want to be able to list the files in a given conda package: https://stackoverflow.com/questions/47138241/list-installed-files-of-a-package. Verify that the package is installed in the correct environment (the one your Python binary is part of), and that it includes files in directories that Python looks at (list those paths with `python -m site`). – Martijn Pieters Sep 24 '20 at 22:12
6

I installed miniconda and found all the installed packages in /miniconda3/pkgs

Hezi Zhang
  • 61
  • 1
  • 1
5

One more option using the interpreter:

import site; print(''.join(site.getsitepackages()))

And using a terminal/prompt:

python -c "import site; print(''.join(site.getsitepackages()))"

Also in this case you can easily print one of the directory (in case there are more than one) using own filter

Nick Veld
  • 424
  • 1
  • 5
  • 14
4

You could also type 'conda list' in a command line. This will print out the installed modules with the version numbers. The path within your file structure will be printed at the top of this list.

jeff_carter
  • 145
  • 5
  • conda list, just gave me " packages in environment at /Users/user/anaconda:" as output. The exact location for the packages was required, which is /Users/user/anaconda/lib/python2.7/'. – Codious-JR Apr 22 '16 at 12:40
  • 'conda list' is a very good idea when you want to know from which repository a package was installed. It also shows an installation via pip. So this is a really good tip although it does not answer the question. – Christian4145 Mar 25 '20 at 14:21
  • 1
    This answer actually works for me - not sure why it's downvoted! `conda list`, as its first line, spits out the root of your conda installation; inside that is the `pkgs` folder. – Dan Nissenbaum Apr 19 '20 at 02:22
  • ... actually (re. my preceding comment), inside the root of the `miniconda` installation I find some packages at 'lib/python3.7/site-packages' – Dan Nissenbaum Apr 19 '20 at 02:32
  • my problem is that I see it in conda list but I can't find where it would be located...any ideas? – Charlie Parker Sep 24 '20 at 18:25
2

You should find installed packages in :

anaconda's directory / lib / site_packages

That's where i found mine.

BHA Bilel
  • 171
  • 1
  • 12
2

At least with Miniconda (I assume it's the same for Anaconda), within the environment folder, the packages are installed in a folder called \conda-meta.

i.e.

C:\Users\username\Miniconda3\envs\environmentname\conda-meta

If you install on the base environment, the location is:

C:\Users\username\Miniconda3\pkgs

2

The location should be (in Linux systems):

home/<USERNAME>/anaconda3/envs/<ENV_NAME>/lib/python<VERSION>/site-packages/
Rafay Khan
  • 748
  • 6
  • 21
0

I encountered this issue in my conda environment. The reason is that packages have been installed into two different folders, only one of which is recognised by the Python executable.

~/anaconda2/envs/[my_env]/site-packages ~/anaconda2/envs/[my_env]/lib/python2.7/site-packages

A proved solution is to add both folders to python path, using the following steps in command line (Please replace [my_env] with your own environment):

  1. conda activate [my_env].
  2. conda-develop ~/anaconda2/envs/[my_env]/site-packages
  3. conda-develop ~/anaconda2/envs/[my_env]/lib/python2.7/site-packages (conda-develop is to add a .pth file to the folder so that the Python executable knows of this folder when searching for packages.)

To ensure this works, try to activate Python in this environment, and import the package that was not found.

Huanfa Chen
  • 547
  • 5
  • 14