Where to install pip packages inside my Conda environment?

10,935

No Specification Needed

Fortunately, one need not manually specify where to install the packages. Instead, if one uses the pip associated with the environment, packages will install to the site-packages directory of environment's python by default.

Example

 > conda activate venv_name
 
 # check that you are using the right pip
 > which pip
 /Anaconda3/envs/venv_name/bin/pip  # should be something like this

 > pip install <package name>

This will install packages into /Anaconda3/envs/venv_name/lib/python3.7/site-packages/, or whatever Python version you have installed for the environment.

⛔️ Important Note: There are some flags for pip install that change this behavior, most notably the --user flag. Conda users are strongly discouraged from using this flag because it installs packages at a user-level, leading to packages being visible to other environments with matching Python versions (major+minor).

Caution: Mixing PyPI and Conda Packages

Be aware that (as @WilliamDIrons pointed out), it is usually preferable to use conda install -n venv_name <package name> instead of pip. The common practice is to only use pip in a Conda environment when the package is not available through a Conda repository. It is strongly recommended to read and follow the best practices found in the "Using pip in an environment" documentation.

Share:
10,935
Nick T
Author by

Nick T

Updated on June 13, 2022

Comments

  • Nick T
    Nick T almost 2 years

    As I understand it, if I use pip install ___, that package will go to my global version of python. If I change directory to the within my Conda environment then that package will be isolated within the environment. Is this correct?

    I have searched to try and find where to put the pip packages (within my Conda environment). It used to be that you would install the pip packages in /Anaconda3/envs/venv_name/bin/. It appears the bin folder is now located within the Library folder, like this: /Anaconda3/envs/venv_name/Library/bin. Is the bin folder still the recommended place to put the packages installed by pip?

    In other words should I be placing the pip installed packages here: /Anaconda3/envs/venv_name/Library/bin ?

  • William D. Irons
    William D. Irons about 5 years
    To add to the answer, whenever possible use conda install <package name> instead of pip install <package name> to install the conda version of the package.
  • merv
    merv about 5 years
    @NickT, which pip is just to show you that you can check which copy of pip you are about to run in the actual command (pip install <package name>). You don't have to run that. I only included it because sometimes people have conda envs that don't have pip installed. If that is the case, you should install it via conda install pip. Otherwise, you might inadvertently use your system's pip and wonder why you can't find your packages.