2

I have an environment.yml file which creates the environment:

name: blah

channels:
  - conda-forge

dependencies:
  - python=3.9
  - psychopg2

  # THESE ARE FOR LOCAL DEV ONLY
  - jupyter
  - ipykernel
  - folium

There is a huge saving in the docker image size if the local dev packages are excluded from production. But those packages are needed for local testing on development machines etc.

My current solution is to maintain a separate environment_local.yml to run locally which includes these packages, but run environment.yml during the docker build which excludes them. But there is the potential for the files to get out of sync in shared dependencies.

Is there a way to exclude packages from the environment based on a command line flag? Or, can environment files inherit and extend each other?

Brendan Hill
  • 3,406
  • 4
  • 32
  • 61
  • Possible duplicate: https://stackoverflow.com/q/69548005/570918 Please ping me if you agree. – merv Nov 23 '21 at 07:48
  • agree it is a duplicate yes.... – Brendan Hill Nov 24 '21 at 00:32
  • although I think thread gies a simpler answer...https://stackoverflow.com/questions/42352841/how-to-update-an-existing-conda-environment-with-a-yml-file – Brendan Hill Nov 24 '21 at 00:33
  • 1
    Yeah, the other one is complicated because the user wanted to guarantee that dev and prod envs use *completely identical package builds*. That’s great for professional engineers, but overkill for less formal settings. – merv Nov 24 '21 at 01:06

1 Answers1

3

With some How to update an existing Conda environment with a .yml file

the solution I went for was:

environment.yml:

name: blah

channels:
  - conda-forge

dependencies:
  - python=3.9
  - psychopg2

environment.local.yml:

channels:
  - conda-forge
  - anaconda

dependencies:
  - folium
  - ipykernel
  - jupyter

Configuring for production environment:

conda env create -f environment.yml

Configuring for local environment:

conda env create -f environment.yml
conda env update -f environment.local.yml
Brendan Hill
  • 3,406
  • 4
  • 32
  • 61
  • 1
    Did you manually create both files? Or is there a way to give conda a list of packages to include in each file? I am currently working on a slightly larger project and it's impossible to tell which packages depend on what when looking at the long list shown by `conda env export`. So I'm hoping to somewhat keep all jupyter & ipykernel (and their dependencies) in one environment file and everything else in another, all from the command line. – olamarre Sep 03 '22 at 14:52