1

Here is my script. I have an env called myenv previously setup.

I know that I'm sourcing conda correctly, becuase if I deliberately hand the script a bad environment name, it outputs an error message. But if I call it with myenv, it runs but doesn't do anything. My environment stays as (base).

#!/bin/zsh
# MAKE SURE YOU HAVE MINICONDA INSTALLED

CONDA_BASE=$(conda info --base)    

source $CONDA_BASE/etc/profile.d/conda.sh

conda activate myenv

I'm using MacOS Catalina. Everything else is set up correctly, and every other conda command works. The only reason I can think of is that my shell is for some reason cancelling the command... It's a bit baffling.

I'd appreciate any help with this issue.

merv
  • 67,214
  • 13
  • 180
  • 245
Raph117
  • 3,441
  • 7
  • 29
  • 50
  • 1
    So you are running the script (i.e. something linke ./), it runs, but your environment is not changing(in the shell from which you ran ./) as you expect – FlyingTeller Oct 09 '20 at 11:51
  • Yes that's exactly it – Raph117 Oct 09 '20 at 12:24
  • Scripts you run happen in a new interpreter, not the one you're interactively typing commands in. Consequently, they can't change the state of that preexisting interactive interpreter. Assuming (and this is a significant assumption) `conda activate` is calling a shell function that changes the state of your existing shell, it's not expected to have any further effect after the script it's called in exits. – Charles Duffy Oct 10 '20 at 01:37
  • Actually, that's not a significant assumption at all. If it weren't true you wouldn't need to source in `conda.sh` before you could call `conda activate`. – Charles Duffy Oct 10 '20 at 01:39

1 Answers1

0

For your script to modify the state of your interactive shell, you need to either source it into your interpreter, or define it as a function rather than a script at all.

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441