1

I am trying to get the anaconda version here, when I run conda list anaconda I get the following result: enter image description here

I want to be able to get the value 2019.10, I am not aware how to do so, I tried to get the type of conda list anaconda to know even how to deal with it, but I get error. Is there a way I can get the version which is 2019.10 here?

Mee
  • 1,413
  • 5
  • 24
  • 40
  • Just a method issue but you should always prefer pasting text with the code block using ``` ``` instead of uploading photos. Images links tend to not last on the long term, and questions and answer lasting is a goal of stack overflow. – Osamoele Sep 03 '21 at 16:23
  • Your question is not clear. The command you used show you the anaconda version. It is ``2019.10`` for you, as shown on your image. What's the matter then ? Do you want to programmatically get the version number inside a variable in python ? – Osamoele Sep 03 '21 at 16:27
  • In that case, the answer from @kthy in that thread https://stackoverflow.com/questions/48342098/how-to-check-python-anaconda-version-installed-on-windows-10-pc should help you. – Osamoele Sep 03 '21 at 16:32
  • Thanks for your comment, yes but in this case I still need to know the version of Anaconda to open the file itself as the file name itself has the anaconda version, right? – Mee Sep 07 '21 at 07:40
  • Not necessarily. You could use regular expressions to match the file name, whatever the version, and extract the part that interests you from the file content or directly the file name. – Osamoele Sep 08 '21 at 00:29
  • You still have to assume that the anaconda file will be located at the same place from user to user though. I guess using python subprocess to run the CLI version of the "get anaconda version solution" isnmore robust. And from that, extract the info printed on the cmd to use it in python... – Osamoele Sep 08 '21 at 00:33

1 Answers1

1

If you just want that string then:

conda list '^anaconda$' | tail -n1 | tr -s' ' | cut -f2 -d' '

or maybe more robust

conda list -e '^anaconda$' | awk -F'=' '!/^#/ {print $2}'
merv
  • 67,214
  • 13
  • 180
  • 245