Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I see the creation dates for my conda environments?

I created four different versions of conda virtual environments (envs) for image processing tasks. Each env includes GDAL and OpenCV, and some subset of related libs and dependencies. I want to cull my list of image processing envs down to the most recently created one, which will have the most complete set of the libs I use. But I don't remember the order I created the envs.

Is there a way to see the creation date of individual envs or perhaps a list of creation dates for all of my conda envs?

UPDATE

Here is the output of the command suggested by @Timur Shtatland

$ conda env list -v -v -v | grep -v '^#' | perl -lane 'print $F[-1]' | xargs ls -lrt1d
$ miniconda3/envs/opencv2_imgproc
$ miniconda3/envs/GDAL_OSGEO_env
like image 460
someguyinafloppyhat Avatar asked Oct 29 '25 06:10

someguyinafloppyhat


2 Answers

Use conda env list to print to STDOUT the list of conda environments and the env paths. Follow this by ls -lrt1d <env paths>, which prints to STDOUT the paths sorted by time:

conda env list
# conda environments:
#
# base                  *  /Users/user_name/miniconda3
# ...
# bioperl                  /Users/user_name/miniconda3/envs/bioperl
# biopython                /Users/user_name/miniconda3/envs/biopython
# ...

ls -lrt1d env_paths
# Example:
# ls -lrt1d /Users/user_name/miniconda3/envs/bio*

Putting it all together:

conda env list | grep -v '^#' | perl -lane 'print $F[-1]' | xargs ls -lrt1d
like image 62
Timur Shtatland Avatar answered Oct 31 '25 12:10

Timur Shtatland


Conda history files

Aside from file/folder dates, Conda also records the history of all environment changes in the conda-meta/history file relative to each environment folder, so that could also be consulted. All entries begin with a date stamp (==> YYYY-MM-DD HH:MM:SS <==), so assuming the first entry corresponds with env creation, one could do something like

#!/bin/bash

for env_hist in path/to/envs/*/conda-meta/history; do
    env_prefix=$(dirname $(dirname $env_hist))
    echo "$(head -n1 $env_hist) $env_prefix"
done | sort

to print something like

==> 2020-09-28 16:12:49 <== path/to/envs/pymc39
==> 2020-11-08 18:15:26 <== path/to/envs/bioc_3_12
==> 2020-11-22 17:19:08 <== path/to/envs/snakemake_5_29
==> 2021-01-23 00:08:33 <== path/to/envs/pymc3_11
==> 2021-01-23 00:12:53 <== path/to/envs/jupyter
==> 2021-03-09 22:50:38 <== path/to/envs/multiqc
==> 2021-03-24 13:20:07 <== path/to/envs/grayskull
==> 2021-04-05 23:40:01 <== path/to/envs/snakemake_6_1
like image 28
merv Avatar answered Oct 31 '25 11:10

merv