Unable to activate the mounted conda environment

The conda environment is created in linux called (L1) using

conda create --prefix /anaconda_env/personal/env1 python=3.6

I mount the conda environment in the linux called (L2). 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.

I also tried using

conda activate /anaconda_env/personal/env1

But it also does not work. May I know how can I solve this issue?

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


-- coding: utf-8 --

import sys

Before any more imports, leave cwd out of sys.path for internal β€˜conda shell.*’ commands.

see source activate <env> does not work from command line in a folder containing io.py Β· Issue #6549 Β· conda/conda Β· GitHub

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

1 Like

dear 9.susan2.

thank you for posting.

The conda command, like pyenv, creates an environment alias, and an error will occur if the alias name is missing.

Therefore, you should change the following command as below.

conda create --prefix /anaconda_env/personal/env1 python=3.6


conda create -n py36 --prefix /anaconda_env/personal/env1 python=3.6

Aliases created in this way are created in the /anaconda_env/personal/env1 directory.

And to use the new alias so created,

(base) $ conda activate py36

will do.

Regards, you.

Hello Ktsh.tanaka,

Thank you for your reply.
conda activate py36 is okay in the linux (L1) which I used to create the environment.
But the issue is in the another linux (L2) which mount the environment from L1.
I don’t know why I got the error in linux (L2).

1 Like

Hello ktsh.tanaka,

May I know do I need to install conda in linux (L2)?
Because when I check conda version

conda --version
I got the same error. But in linux (L1), I can check the conda version. The conda version in L1 is 4.8.3.

1 Like

dear 9.susan2.

thank you for reply.
The cause is unknown, but it seems that the error occurs because python lib or json under info cannot be read in the L2 environment.

Below is the tree of libraries used by conda (URL: Conda packages β€” conda dev documentation).

β”‚ └── pyflakes
β”‚ β”œβ”€β”€ LICENSE.txt
β”‚ β”œβ”€β”€ files
β”‚ β”œβ”€β”€ index.json
β”‚ β”œβ”€β”€ paths.json
β”‚ └── recipe
└── lib
└── python3.x

When using conda with bash, csh, etc., the necessary PATH is set through a shell script in $HOME\anaconda3\etc\profile.d.

However, I think it is caused because it is not enabled on the L2 side.

Therefore, as a solution, I think it is better to allow the L2 environment side to refer to the necessary libraries.

Regards, you.