2

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())
Susan
  • 431
  • 1
  • 4
  • 16
  • How did you create new environment env1 using terminal? – AnhPC03 Aug 08 '22 at 03:27
  • I create new environment in the terminal in the other linux called L2. ```conda create --prefix /anaconda_env/personal/env1 python=3.6``` In this linux called L1, I mounted the anaconda and activate that environment (env1). – Susan Aug 08 '22 at 04:35
  • Could you check if this path `/anaconda_env/miniconda/bin/python` exists or not? – AnhPC03 Aug 08 '22 at 06:54
  • @AnhPC03, yes there is python file in /anaconda_env/miniconda/bin folder. – Susan Aug 08 '22 at 06:57
  • @AnhPC03, I also mounted in the another linux (L3) and activate the environment. There is no problem in L3. The environment is activated. This linux (L1) is a new server and I just mount the environment and activate it that I did the same step for other linux (L3). I am not sure whether do I need to install something before mounting the environment in the new linux system. May I know do I need to install conda? Because when I check the conda --version, it gives the same issue. – Susan Aug 08 '22 at 06:58
  • In L3, inside file `miniconda/bin/conda` has the same content within L1, right? – AnhPC03 Aug 08 '22 at 07:02
  • Could you check if your L1 machine has `python` installed? – AnhPC03 Aug 08 '22 at 07:03
  • @AnhPC03, when I check ```python --version``` in L1 machine, it gives python 2.7.18. and ```python3 --version```, it gives python 3.8.10. L1 and L3 are mounting the miniconda folder from L2 machine. Both L1 and L3 have the same files inside the miniconda/bin folder. – Susan Aug 08 '22 at 07:10
  • Have you checked `/anaconda_env/miniconda/bin/python --version` in L1 and L3? – AnhPC03 Aug 08 '22 at 07:14
  • @AnhPC03, may I know how to check the python version from /anaconda_env/miniconda/bin in linux? May I know should I go to the folder ```cd /anaconda_env/miniconda/bin``` and ```python --version```? – Susan Aug 08 '22 at 07:16
  • You should explicit the path `/anaconda_env/miniconda/bin/python` to check exactly use python in bin folder. So could you check `/anaconda_env/miniconda/bin/python --version` in L1 and L3? – AnhPC03 Aug 08 '22 at 07:18
  • @AnhPC03, sorry, I am not sure how can I explicit the path in linux. python is a file inside /anaconda_env/miniconda/bin/ folder. – Susan Aug 08 '22 at 07:22
  • Could you type `/anaconda_env/miniconda/bin/python --version` in L1 and L3? and show me the output. – AnhPC03 Aug 08 '22 at 07:25
  • @AnhPC03 In L1 machine, ```-bash: /anaconda_env/miniconda/bin/python: cannot execute binary file: Exec format error```. But in L3 machine, it gives ```Python 2.7.15``` – Susan Aug 08 '22 at 07:27
  • Try running `sudo apt-get install gfortran && sudo apt-get install build-essential` in L1 machine and try again – AnhPC03 Aug 08 '22 at 07:31
  • @AnhPC03, after installing the gfortran and build-essentioal in L1 machine using ```sudo apt-get install gfortran && sudo apt-get install build-essential``` and check the python version ```/anaconda_env/miniconda/bin/python --version```. It gives the same error ```-bash: /anaconda_env/miniconda/bin/python: cannot execute binary file: Exec format error``` I also restarted the L1 machine and check again. I got the same issue in L1 machine. – Susan Aug 08 '22 at 07:37
  • Could you show me output of `file /anaconda_env/miniconda/bin/python` and `uname -a` in machine L1? – AnhPC03 Aug 08 '22 at 07:38
  • @AnhPC03, ``` file /anaconda_env/miniconda/bin/python``` gives ```/anaconda_env/miniconda/bin/python: symbolic link to python2.7```. uname -a is Linux odroid 4.9.277-122 #1 SMP PREEMPT Mon Feb 28 14:30:14 UTC 2022 aarch64 aarch64 aarch64 GNU/Linux – Susan Aug 08 '22 at 07:39
  • And the output of `uname -a` in L2 and L3? – AnhPC03 Aug 08 '22 at 07:41
  • For L2 --> ```Linux sys2s 3.10.0-693.17.1.el7.x86_64 #1 SMP Sun Jan 14 10:36:03 EST 2018 x86_64 x86_64 x86_64 GNU/Linux``` For L3 --> ```Linux sys3s 4.4.0-189-generic #219-Ubuntu SMP Tue Aug 11 12:26:50 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux``` – Susan Aug 08 '22 at 07:44
  • And this is your problem, the L2, L3 have the same architecture is `x86_64`, L1 has different architecture is `aarch64`, so binary file `python` of L2 machine cannot be executed on L1 machine – AnhPC03 Aug 08 '22 at 07:45
  • May I know how can I compile the binary file for python to be able to execute on L1 machine which use aarch64 architecture? Because I need to mount the conda environment from L2 machine. – Susan Aug 08 '22 at 07:47
  • Can I see output of `ls -al /anaconda_env/miniconda/bin/python` in your L2? – AnhPC03 Aug 08 '22 at 07:49
  • @AnhPC03 but when we check the binary python file using ```file /anaconda_env/miniconda/bin/python```. It does not show what file format is compiled like x86-64 or 64 bit or 32 bit. it just said ```symboic link to python2.7``` – Susan Aug 08 '22 at 07:50
  • @AnhPC03, ```lrwxrwxrwx 1 root root 9 Jun 18 2022 /anaconda_env/miniconda/bin/python -> python2.7``` – Susan Aug 08 '22 at 07:51
  • Type `ls /anaconda_env/miniconda/bin | grep python` in L2 and `ls -al /anaconda_env/miniconda/bin/python2.7` in L2? – AnhPC03 Aug 08 '22 at 07:53
  • @AnhPC03, in L2, ```ipython ipython2 python python2 python2.7 python2.7-config python2-config python-config``` ```-rwxrwxr-x 1 root root 19776 Jun 18 2022 /anaconda_env/miniconda/bin/python2.7``` – Susan Aug 08 '22 at 07:58
  • Could you show `which python` in L1? – AnhPC03 Aug 08 '22 at 08:04
  • In L1, the output is the same as L2. But when I check ```file /anaconda_env/miniconda/bin/python2.7``` it is ```/anaconda_env/miniconda/bin/python2.7: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, with debug_info, not stripped```. Is it related to this python 2.7 binary file which is for x86-64 architecture? – Susan Aug 08 '22 at 08:08
  • You are mounting L1 to L2, so the `python` binary of L2 cannot be executed in L1. Show me `which python` in L1 and I could give you some try – AnhPC03 Aug 08 '22 at 08:10
  • In L1, which python is ```/usr/bin/python```. Yes L1 machine is mounting the anaconda_env to L2. – Susan Aug 08 '22 at 08:12
  • Show me output of `ls -al /usr/bin | grep python` in L1 – AnhPC03 Aug 08 '22 at 08:13
  • The output of ```ls -al /usr/bin | grep python``` in L1 --> ```-rwxr-xr-x 1 root root 1057 dh_python2 lrwxrwxrwx 1 root root 23 pdb2.7 -> ../lib/python2.7/pdb.py lrwxrwxrwx 1 root root 23 pdb3.8 -> ../lib/python3.8/pdb.py lrwxrwxrwx 1 root root 31 py3versions -> ../share/python3/py3versions.py lrwxrwxrwx 1 root root 7 python -> python2 lrwxrwxrwx 1 root root 9 python2 -> python2.7 -rwxr-xr-x 1 root root 3593112 python2.7``` – Susan Aug 08 '22 at 08:15
  • ```lrwxrwxrwx 1 root root 9 python3 -> python3.8 -rwxr-xr-x 1 root root 384 python3-futurize -rwxr-xr-x 1 root root 388 python3-pasteurize -rwxr-xr-x 1 root root 5238784 python3.8 lrwxrwxrwx 1 root root 29 pyversions -> ../share/python/pyversions.py``` – Susan Aug 08 '22 at 08:16
  • Ok, try `ln -s /usr/bin/python2.7 /anaconda_env/miniconda/bin/python` in L1 and try `conda --version` again – AnhPC03 Aug 08 '22 at 08:17
  • if I did softlink to the python, I cannot use the previous binary python 2.7 for x86-64 architecture? Because x86-64 architecture linux machines are using the python . – Susan Aug 08 '22 at 08:22
  • 1
    You are right, so my suggestion is do not mount two different architecture machine, install new conda env to L1 and freeze packages from L2 and install to L1. Because if you can mount and run conda in L1, installed packages in L2 still cannot be executed in L1 because of different architectures – AnhPC03 Aug 08 '22 at 08:25
  • Thank you for the suggestion. May I know how can I install new conda environment to L1. One thing is I want to install the same packages used in env1 which has created in L2 when I install new conda environment in L1. Can you suggest how can I do? – Susan Aug 08 '22 at 08:31
  • You can create new environment in L1 using `conda create --prefix /anaconda_env/personal/env1 python=3.6`. In L2, freeze all installed packages using `conda list --export > requirements.txt`. Then you can mount `requirements.txt` file between L1, L2. In L1, you run `conda install --file requirements.txt` to synchronize packages – AnhPC03 Aug 08 '22 at 08:35
  • L1 does not have anaconda in linux. It is totally new machine and doesn't have /anaconda_env/personal/ folder. Do I need to install anaconda first? Also conda command is not found in L1. – Susan Aug 08 '22 at 08:38
  • Yes, you need to install anaconda or miniconda for lighter in L1 – AnhPC03 Aug 08 '22 at 08:40
  • Can you suggest any document of how to install minicoda in linux @AnhPC03? – Susan Aug 08 '22 at 08:41
  • See [this](https://docs.conda.io/en/latest/miniconda.html#linux-installers), download installing file containing `aarch64`. After that, install miniconda using `bash /path/to/downloaded/file` to install – AnhPC03 Aug 08 '22 at 08:58
  • @AnhPC03, [verify the installer hash] (https://conda.io/projects/conda/en/latest/user-guide/install/linux.html) step is I need to verify whether the [SHA256 hash](https://conda.io/en/latest/miniconda_hashes.html) in the table is the same as the one that I get from the linux terminal ? ```sha256sum Miniconda3-py37_4.12.0-Linux-aarch64.sh``` ```47affd9577889f80197aadbdf1198b04a41528421aaf0ec1f28b04a50b9f3ab8 Miniconda3-py37_4.12.0-Linux-aarch64.sh``` – Susan Aug 08 '22 at 09:24
  • Yes, you can verify the downloaded file or I usually pass this step :) – AnhPC03 Aug 08 '22 at 09:30
  • @AnhPC03, thank you for suggestion. I got condaHTTPError when I create the environment in L1. Do you know how to solve this issue? ```Collecting package metadata (current_repodata.json): failed CondaHTTPError: HTTP 000 CONNECTION FAILED for url Elapsed: - An HTTP error occurred when trying to retrieve this URL. HTTP errors are often intermittent, and a simple retry will get you on your way.``` – Susan Aug 10 '22 at 02:20

2 Answers2

1

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

juanpa.arrivillaga
  • 88,713
  • 10
  • 131
  • 172
  • Hello Juanpa, I also tried with ```conda activate /anaconda_env/personal/env1```. I got the same error message. Because I think when I also checked ```conda --version```, the error is still there. – Susan Aug 08 '22 at 04:38
0

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
merv
  • 67,214
  • 13
  • 180
  • 245