shelper
shelper

Reputation: 10583

how to reuse global site-packages in conda env

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?

Upvotes: 11

Views: 23347

Answers (3)

NMntn
NMntn

Reputation: 76

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.

Upvotes: 6

jaimedash
jaimedash

Reputation: 2743

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).

Upvotes: 5

aquagremlin
aquagremlin

Reputation: 3549

You could use the PYTHONPATH environment variable. For example

export PYTHONPATH="/Users/me/anaconda/lib/python2.7/site-packages:$PYTHONPATH"

would give every environment access to all the libraries in the anaconda distribution. Sort of defeats the purpose of environments though. And if you then want access to a library you installed with home-brew as well, you would add

export PYTHONPATH=/usr/local/Cellar/another_package/lib/python2.7/site-packages:$PYTHONPATH

Upvotes: 0

Related Questions