unable to activate the mounted conda environment

Viewed 75

I mount the conda environment in the linux. Then I activate the environment in the linux.

export PATH=$PATH:/opt/miniconda/bin
source activate /anaconda_env/personal/env1

Then I got this error:

/anaconda_env/miniconda/bin/conda: line 3: import: command not found
/anaconda_env/miniconda/bin/conda: line 6: syntax error near unexpected token `sys.argv'
/anaconda_env/miniconda/bin/conda: line 6: `if len(sys.argv) > 1 and sys.argv[1].startswith('shell.') and sys.path and sys.path[0] == '':'

When I check conda --version, the same error is shown.

Can anyone help me with this?

Inside the miniconda/bin/conda, the script is as follow

#!/anaconda_env/miniconda/bin/python
# -*- coding: utf-8 -*-
import sys
# Before any more imports, leave cwd out of sys.path for internal 'conda shell.*' commands.
# see https://github.com/conda/conda/issues/6549
if len(sys.argv) > 1 and sys.argv[1].startswith('shell.') and sys.path and sys.path[0] == '':
    # The standard first entry in sys.path is an empty string,
    # and os.path.abspath('') expands to os.getcwd().
    del sys.path[0]

if __name__ == '__main__':
    from conda.cli import main
    sys.exit(main())
2 Answers

I'm not exactly sure what is going on, it seems like you are running the /anaconda_env/miniconda/bin/conda using source, but it isn't a shell program.

Instead of:

source activate /anaconda_env/personal/env1

Do:

conda activate /anaconda_env/personal/env1

Which is the way it should be done, I think miniconda/bin/activate is legacy and the correct way is to use conda activate

The answer from @juanpa.arrivillaga has part of the story. Another part is getting conda defined properly in the shell.

This should not be done by explicitly manipulating PATH. Rather, Conda generates all the stuff that needs to be run, which includes additional environmental variables and shell functions. In this context, I expect one wants:

## initialize `conda`
eval "$('/opt/miniconda/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
## alternative approach


## activate environment
conda activate /anaconda_env/personal/env1
Related