how to reuse global site-packages in conda env

13,810

Solution 1

In case anyone is coming back to this now, for conda 4.7.12, entering export PYTHONNOUSERSITE=True before the conda activate call successfully isolated the conda environment from global/user site packages for me.

On the other hand, entering export PYTHONNOUSERSITE=0 allows the conda environment to be reintroduced to the global/user site packages.

Note: This is instead of the previously suggested export PYTHONNOUSERSITE=1.

Solution 2

you cannot do this explicitly in conda, where the principle is that envs are entirely separate.

but the current default behavior of conda is to allow all global user site-packages to be seen from within environments, as mentioned in this question. so, the default behavior will allow you to do as you wish, but there is no way to allow only "some specific" global packages as requested.

this behavior has caused one or two issues. to avoid it, export PYTHONNOUSERSITE=1 before source activate <your env>. note that the devs are planning to change the default behavior to set PYTHONNOUSERSITE=1 in 4.4.0 (per the second issue linked).

Share:
13,810
shelper
Author by

shelper

Updated on July 26, 2022

Comments

  • shelper
    shelper almost 2 years

    I have a project called ABC, I have a conda env just for it in the fold ~/anaconda/envs/ABC, I believe it is a venv, and I want to use some specific packages from the global site packages.

    For normal Python installation it can be done be removing the no-global-site-package.txt from the venv folder, or by setting the venv to use global-site-packages, but I didn't find any equivalent approach to do this in Anaconda. The online documentation does not have answer either.

    How to do this for Anaconda?

  • aquagremlin
    aquagremlin about 7 years
    Well Dominick, can you explain yourself?
  • citynorman
    citynorman over 5 years
    I have conda 4.5.8 and export PYTHONNOUSERSITE=1 before source activate didn't do anything for me, it still has all global libraries :(
  • jaimedash
    jaimedash about 5 years
    I can't reproduce user citynorman's issue. with conda 4.5.11 on windows, the following did not include global libs in the tmp env conda list > /tmp/global.txt; conda create -n tmp python=3.6; PYTHONUSERSITE=1 source activate tmp; conda list > /tmp/local.txt; diff /tmp/global.txt /tmp/local.txt # files differ