user3029690
user3029690

Reputation: 45

Conda env activation: Weird "must be sourced" error

I am trying to run the following:

source activate env-name

But I am receiving an error that tells me that the call to activate must be sourced. In the Conda activate script, there's an if block near the beginning that tests "$(basename "$0")", specifically whether it's equal to activate, in which case it will raise the exception I'm referring to. A little bit of fiddling with the script (i.e., echo $0; return 1) and I found out that it does indeed think that the 0th argument that I am passing in is activate rather than source. This is perplexing because I know that my command includes source in it and that that should be the 0th argument. I'm not sure what else there is to do. Does anybody have any clues?

In case it's important, I am using zsh as my default shell and it seems that the activate script is a bash script, but I don't think that should matter (it doesn't elsewhere for me, only in this specific environment on my work laptop). I am able to get around this whole thing by just commenting out the whole check (and a couple of other minor changes), but I'd rather not have to do that in this particular case.

Upvotes: 4

Views: 3242

Answers (3)

nirvana-msu
nirvana-msu

Reputation: 4067

I got similar error because I was using asdf-vm which masks actual binaries with shims. As documented here, scripts that need to be sourced must be accessed directly because asdf uses exec system call. So in my case, the following command worked:

source $(asdf which activate) <ENV NAME>

While this answer is specific to asdf, the error you're getting suggests you were in a similar situation where the call to activate was intercepted by some other executable.

Upvotes: 0

Jung
Jung

Reputation: 66

** I DON'T HAVE ENOUGH REPUTATION, SO I REPLY THIS. (I wanna just comment but I can't)

It can be solve that you know this.
"Run 'Source activate envname'" means you have to run this command on correct path or directory.

If you install anaconda3 on /home/user/anaconda3/ your correnct source path is /home/user/anaconda3/bin/

/home/user/anaconda3/bin/ activate tensorflow

or

cd /home/user/anaconda3/bin
. activate tensorflow

So, I already solve this problem through adding path(or move correct path)

Upvotes: 0

The Ref
The Ref

Reputation: 744

I've been having the same issue, the only workaround I've found is:

source <PATH TO ANACONDA>/anaconda3/bin/activate <ENV NAME>

EDIT: adding the line:

export PATH=$PATH:<PATH TO ANACONDA>/anaconda3/bin:$PATH

to your bashrc (or zsh etc) will add source to your path and you will be able to use source as normal.

Upvotes: 4

Related Questions