conda export environment and conda import environment

conda export and import feature is ideal functionality to build a predefined environment from a list in a text file.
Here are some caveats (or features), which may stumble the user to build a working conda environment list file:

  • There are packages, which are not available for all OS platforms. There are packages, which are only available in Linux platforms and other only under Windows platform!
  • There are package names, followed by version and build version. All three a valid entries in the list file – only the name of the package, the name of the package with version and the name of the package with version and build version. For example,
      - setuptools=58.0.4=py38h06a4308_0
      - sqlite=3.37.0=hc218d9a_0
      - tk=8.6.11
      - wheel
  • Builds’ versions are specific for the OS and they are different for every Operating systems.
  • Packages’ versions do tend to deprecate, so the old environment may not be possible to replicate because of a missing package version. Exported list with version, which are unavailable any more and so it cannot be imported.
  • A good practice is to update the current working environment with the latest updates before exporting it.
  • Export environment list without build versions. Edit the exported environment list if some version is missing. The version of the packages could be removed, too.
  • The exported environment list uses yaml format.

1) Here is the command to export an environment list of a python environment with and without builds and versions of the packages:

  1. With builds versions
    (base) myenv@srv ~ $ conda env export -n mypython37
    name: mypython37
      - defaults
      - _libgcc_mutex=0.1=main
      - _openmp_mutex=4.5=1_gnu
      - ca-certificates=2021.10.26=h06a4308_2
      - certifi=2021.10.8=py37h06a4308_2
      - ld_impl_linux-64=2.35.1=h7274673_9
      - libffi=3.3=he6710b0_2
      - libgcc-ng=9.3.0=h5101ec6_17
      - libgomp=9.3.0=h5101ec6_17
      - libstdcxx-ng=9.3.0=hd4cf53a_17
      - ncurses=6.3=h7f8727e_2
      - openssl=1.1.1m=h7f8727e_0
      - pip=21.2.2=py37h06a4308_0
      - python=3.7.11=h12debd9_0
      - readline=8.1.2=h7f8727e_1
      - setuptools=58.0.4=py37h06a4308_0
      - sqlite=3.37.0=hc218d9a_0
      - tk=8.6.11=h1ccaba5_0
      - wheel=0.37.1=pyhd3eb1b0_0
      - xz=5.2.5=h7b6447c_0
      - zlib=1.2.11=h7f8727e_4
    prefix: /home/myenv/miniconda3/envs/mypython37

    By default, the output is in the console with YAML syntax. There is a JSON option and a file option to output it in a file:
    Keep on reading!