Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can packages be shared across Anaconda environments?

My ~/anaconda directory is taking up too much disk space (10GB), although I have only five environments and have run conda clean. I discovered that when I try to create a new conda environment, Anaconda displays a very long list of packages to be downloaded, which seems to include a full scientific Python stack (Python interpreter, numpy, scipy, etc.). It seems that Anaconda is installing everything independently for each environment. Is this true?

The following list contains some purely speculative ways which could potentially solve the space problem:

  • Can I create a "sub-environment" which "inherits" the packages of a "parent environment"?
  • Can Anaconda be made to share (e.g. via symbolic links on the file system) the same packages used in different environments?
  • Does the default environment have any special status in terms of package managing? I use Anaconda 2, but most of my environments use Python 3. Can I save space by switching to Anaconda 3? (This is regarding the default environment as the "parent environment" of all other environments.)
  • I normally use pip to install packages, as conda install often fails. Does conda install do some smart job to reuse packages already installed somewhere else?

(Debugging information) The sizes of my four environment directories under ~/anaconda/envs are between 1.2GB and 2.6GB. Is this normal?

like image 613
user31039 Avatar asked May 17 '18 15:05

user31039


People also ask

Can conda environments share packages?

By default, conda creates a new environment folder and installs all the packages inside . conda folder in your home directory but this space is limited and cannot be shared with other users.

How do I install packages in Anaconda in another environment?

Go to Environments tab just below the Home tab and from there we can check what all packages are installed and what is not. It is very easy to install any package through anaconda navigator, simply search the required package, select package and click on apply to install it.

Are conda environments independent?

Virtual environments depend on the base system install of Python, whereas Conda environments are independent of the base install.

Where does Anaconda store site packages?

Conda installs packages into the anaconda/pkgs directory. If conda cannot find the file, try using an absolute path name instead of a relative path name. Installing packages directly from the file does not resolve dependencies.


1 Answers

I believe the answer to your main question lies in the difference between Anaconda vs Miniconda. Anaconda includes a long list of packages that get installed automatically into each environment that you create. Miniconda creates barebone conda virtual environments (which don't contain many packages at all). Switching to Miniconda should substantially reduce the size/number of packages in your environments. Anaconda is about 2GB, while Miniconda is closer to 100MB.

Conda also uses hardlinks for packages installed vs conda install. A good description of hardlinks can be found here. They basically link dependencies across multiple environments like you've described above. Packages installed via pip are not hardlinked, so they cannot take advantage of the space savings that conda packages offer.

like image 176
Drew Avatar answered Oct 03 '22 21:10

Drew