4

In using Conda environments, I am not understanding the correct way to access packages that are in the root environment. Especially for development, when I am not sure from the very beginning exactly what packages I will end up needing, having access to easily import packages from base is important!

For example, I need an environment that uses geopandas, but also several packages that are in the base (pandas, os, numpy, glob).

What is the best / "correct" way to do this?

The two methods I have used are:

  1. First clone base environment with conda create --name geoEnv --clone base, and then run further commands to add new packages that are not in the base environment, e.g. coda install geopandas and then, conda install -c conda-forge pysheds (to add something from a specific channel).
  2. Simply create a new environment, and install new packages on the fly as needed. For example, start off with conda create --name geoEnv, activate the environment, and install packages one by one as I go and find I need them, e.g. conda install pandas, conda install glob, all separately. This is time-intensive, download-intensive, and quite annoying.

What is the better way I'm missing here? I wish there was a way to tell Anaconda "if the package I am importing is not in this environment, please import it from the base environment". Is there such a setting?

I've reviewed the anaconda documentation, and stack overflow questions, with no resolution. I WANT the behavior observed in this stack overflow post as a problem ; not sure how to get it!!

EHB
  • 1,127
  • 3
  • 13
  • 24
  • 1
    Conda should not re-download the same package over and over again. Can you share an example of this happening? – AMC Mar 18 '20 at 20:41
  • 2
    No, there is no such setting because it is a limitation of Python itself, not Anaconda. Anyways, the point of conda environments is to isolate dependencies. Probably packages are being downloaded again because you're installing a different version than what is in the base environment. Try specifying exactly the same version that already exists and conda (probably) won't download it. Also, what is wrong with your method 1? – darthbith Mar 19 '20 at 13:14
  • @ darthbith so you're saying my method #1 is the best way to go? – EHB Mar 19 '20 at 17:21
  • @AMC, if I use method #2 above, and launch the environment, it will not let me import base packages like pandas. So, I have to `conda install pandas` again, downloading duplicate packages. – EHB Mar 19 '20 at 18:03
  • 1
    @EHB _if I use method #2 above, and launch the environment, it will not let me import base packages like pandas._ Of course, that would defeat the point of using environments. _downloading duplicate packages_ Again, unless this behaviour is tweaked or the package removed from the cache (by using `conda clean`, for example), `conda install` should not re-download the same package. – AMC Mar 19 '20 at 18:18
  • Is it all clear now, did you figure things out? – AMC Mar 22 '20 at 01:49
  • Concerning #2: one can additionally use the `--offline` flag to constrain solving to only use cached packages. Also, use `conda list -e '^foo$'` to get specific versions and build identifiers for the packages (`foo` being an example package name). – merv Jan 10 '21 at 00:54

0 Answers0