Anaconda site-packages

PythonPython 2.7PipAnaconda

Python Problem Overview


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

Python Solutions


Solution 1 - Python

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.

Solution 2 - Python

Run this inside python shell:

from distutils.sysconfig import get_python_lib
print(get_python_lib())

Solution 3 - Python

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

Solution 4 - Python

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

Solution 5 - Python

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

Solution 6 - Python

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.

Solution 7 - Python

You should find installed packages in : > anaconda's directory / lib / site_packages

That's where i found mine.

Solution 8 - Python

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

Solution 9 - Python

The location should be (in Linux systems):

home/<USERNAME>/anaconda3/envs/<ENV_NAME>/lib/python<VERSION>/site-packages/

Solution 10 - Python

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNyxynyxView Question on Stackoverflow
Solution 1 - PythonArcturus BView Answer on Stackoverflow
Solution 2 - PythonVlad CostinView Answer on Stackoverflow
Solution 3 - PythonSteveView Answer on Stackoverflow
Solution 4 - PythonHezi ZhangView Answer on Stackoverflow
Solution 5 - PythonNick VeldView Answer on Stackoverflow
Solution 6 - Pythonjeff_carterView Answer on Stackoverflow
Solution 7 - PythonBHA BilelView Answer on Stackoverflow
Solution 8 - PythonJames PerezView Answer on Stackoverflow
Solution 9 - PythonRafay KhanView Answer on Stackoverflow
Solution 10 - PythonHuanfa ChenView Answer on Stackoverflow