Run python command from specific conda environment

0 views
Skip to first unread message

mike....@getcruise.com

unread,
May 8, 2018, 12:46:23 PM5/8/18
to conda - Public
I'm looking for a portable one-liner for "conda activate my-env; python [args]". Something like "conda python my-env [args]". My use case involves running conda in a Makefile.

Here's what I'm currently doing. My Makefile looks like this:

mycommand:
. /home/me/miniconda3/etc/profile.d/conda.sh; \
conda activate my-env; \
python -m my.package.main

There are a few issues with this. First, the location of anaconda depends on the user. I can get around that with some effort, e.g., 

     CONDA_ROOT := $(conda info --json -s | python -c "import sys, json; print(json.load(sys.stdin)['conda_prefix']);")

but that's pretty gnarly. In particular, it's not clear to me that this JSON parsing is a "stable" part of the Conda API, since it doesn't seem to be well-documented. Moreover, when you try to activate without the conda.sh script, the error is a little misleading:
   
     Your shell has not been properly configured to use 'conda activate'.

Indeed, my .zshrc file had been configured with this line, but the Makefile doesn't use it. It's hard to track that down.

Is there a conda feature that makes this simpler? Or should I ask for one?


-Mike


Chris Barker

unread,
May 9, 2018, 11:49:18 AM5/9/18
to mike....@getcruise.com, conda - Public
conda execute may be what you are looking for:


-CHB


--
You received this message because you are subscribed to the Google Groups "conda - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to conda+un...@continuum.io.
To post to this group, send email to co...@continuum.io.
Visit this group at https://groups.google.com/a/continuum.io/group/conda/.
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/conda/bf14e700-5b0d-408d-9cb0-3349e614678e%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.



--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris....@noaa.gov

Mike McCoy

unread,
May 9, 2018, 12:45:57 PM5/9/18
to Chris Barker, conda - Public
It seems like conda-execute is pretty close to what I'm looking for, and I'll look into it. Also, thanks for the `conda shell.posix hook` tip. That's much nicer than JSON parsing. 

Thanks for the responses,
-Mike
--
icon_orange

Mike McCoy 
Senior Data Scientist



Confidentiality Note: This message is intended only for the person or entity to which it is addressed. It may contain confidential and/or privileged material. Any review, transmission, dissemination or other use, or taking of any action in reliance upon this message by persons or entities other than the intended recipient is prohibited and may be unlawful. If you received this message in error, please contact the sender and delete it.
Reply all
Reply to author
Forward
0 new messages