12

I would like to specify exact versions inside my conda environment file. I've installed the latest version available by adding an unversioned entry to my environment.yaml, followed by conda env update.

# environment.yaml channels: - conda-forge - bioconda - r - defaults dependencies: - gawk=4.2.1 - plink # new package -- get the latest 

Updated the environment with:

$ conda env update -n myenv -f environment.yaml ... plink-1.90b4-h 100% |#################| Time: 0:00:00 1.63 MB/ 

A specific (latest) version "1.904b4-h" was pulled, but that seems truncated and doesn't reflect exactly a conda package version. How would I go about updating the environment with a version string that conda expects?

4 Answers 4

17

One way I've found is to use conda list to produce a listing of all the packages contained in the environment (it can be optionally filtered to a specific package with -f, in this case "plink"):

$ conda list -n myenv -f plink --json [ { "base_url": null, "build_number": 2, "build_string": "h0a6d026_2", "channel": "bioconda", "dist_name": "plink-1.90b4-h0a6d026_2", "name": "plink", "platform": null, "version": "1.90b4", "with_features_depends": null } ] 

You may omit the --json flag to get a simpler output, which is easier on the eyes but might require grepping/awk'ing:

$ conda list -n genomics-py36 -f plink # packages in environment at /home/foo/envs/myenv: # plink 1.90b4 h0a6d026_2 bioconda 

Note: For your scripts: conda list always exits with code 0, whether a package is found or not.

Then you can modify the environment.yaml file with the exact version:

# environment.yaml updated channels: ... dependencies: ... - plink=1.90b4 ... 
Sign up to request clarification or add additional context in comments.

Comments

3

I think conda list | grep xxx will solve your problem.

Given: We need to check PyTorch version:

conda list | grep PyTorch # Return pytorch 1.10.0 py3.8_cuda11.3_cudnn8.2.0_0 pytorch pytorch-mutex 1.0 cuda pytorch torchaudio 0.10.0 py38_cu113 pytorch torchvision 0.11.1 py38_cu113 pytorch 

Comments

0

Note that conda list, just like grep, uses substring search on package names. So if you want to ensure you are getting the version of an exactly matched package name, then you need to obtain conda list results in JSON format and parse them with jq, e.g. thus - for pandas:

$ conda list pandas --json | jq -r '.[] | select(.name=="pandas") | .version' 1.5.3 

... in an environment where there are 3 packages (installed with pip, which conda list also by default includes) containing the "pandas" substring in their names:

$ conda list pandas # Name Version Build Channel geopandas 0.14.0 pypi_0 pypi pandas 1.5.3 pypi_0 pypi pandas-profiling 3.6.6 pypi_0 pypi 

Comments

0

If only the path to the conda environment is available, use:

conda list -p /path/to/conda/env 

For example:

conda list -p /mnt/home/foo/.conda/envs/env-1a84d20bd797f04a477f57f9157048ae 

For a specific package, such as pandas, add grep like so:

conda list -p /mnt/home/foo/.conda/envs/env-1a84d20bd797f04a477f57f9157048ae | grep pandas 

Example output:

pandas 2.2.3 py313ha87cce1_1 conda-forge 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.