Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 604
shelper Avatar asked Mar 07 '16 02:03

shelper


People also ask

Does conda share packages between environments?

With conda, you can create, export, list, remove, and update environments that have different versions of Python and/or packages installed in them. Switching or moving between environments is called activating the environment. You can also share an environment file.

Where does conda store site packages?

The answer is the site-packages in the sys. path list.

Do conda environments inherit from base?

If you created the new environment using something like conda create --name dell_proj , it will not inherit packages from the base environment. You would have to install the packages you want using conda install .


2 Answers

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

like image 120
jaimedash Avatar answered Oct 02 '22 04:10

jaimedash


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.

like image 39
NMntn Avatar answered Oct 02 '22 04:10

NMntn