Search code examples
bashcondaminiconda

Conda Create Environment - No Compatible Shell found


I have a bash script where i will be creating conda virtual environment and install packages into it. currently we are using conda version 4.5.12 with python 3.6 in my virtual environment.

Am trying to upgrade conda version to 4.9.2 with python 3.6.

conda --version
   4.9.2

This is the command i use inside my script

conda create -y --name virtual_env python=3.6

This Runs and fails during Download and Extracting Packages Step. Below is the Error Report

Traceback (most recent call last):
  File "/root/project/miniconda/lib/python3.9/site-packages/conda/exceptions.py", line 1079, in __call__
    return func(*args, **kwargs)
  File "/root/project/miniconda/lib/python3.9/site-packages/conda/cli/main.py", line 84, in _main
    exit_code = do_call(args, p)
  File "/root/project/miniconda/lib/python3.9/site-packages/conda/cli/conda_argparse.py", line 83, in do_call
    return getattr(module, func_name)(args, parser)
  File "/root/project/miniconda/lib/python3.9/site-packages/conda/cli/main_create.py", line 41, in execute
    install(args, parser, 'create')
  File "/root/project/miniconda/lib/python3.9/site-packages/conda/cli/install.py", line 317, in install
    handle_txn(unlink_link_transaction, prefix, args, newenv)
  File "/root/project/miniconda/lib/python3.9/site-packages/conda/cli/install.py", line 346, in handle_txn
    unlink_link_transaction.execute()
  File "/root/project/miniconda/lib/python3.9/site-packages/conda/core/link.py", line 249, in execute
    self._execute(tuple(concat(interleave(itervalues(self.prefix_action_groups)))))
  File "/root/project/miniconda/lib/python3.9/site-packages/conda/core/link.py", line 712, in _execute
    raise CondaMultiError(tuple(concatv(
conda.CondaMultiError: No compatible shell found!
()

Experts Please help.

Adding briefs of the script

#!/bin/bash

set -e

install_conda_for_linux(){
        #
        # Determine Installation Location for non Windows systems
        #
        #Get path where miniconda needs to get installed and remove if anything exixsts already#
        
        downloaded_file=$base_dir/$conda_file
        output_formatted Removing file: $downloaded_file
        rm -f $downloaded_file

        #
        # Download Miniconda
        #
        output_formatted Downloading Miniconda from: $conda_url '\n' Saving file in: $base_dir

        curl -L $conda_url > $base_dir/$conda_file
       
        #
        # Install Miniconda
        #
        rm -rf $install_dir

        bash $base_dir/$conda_file -b -p $install_dir

        #
        # Modify PATH
        #
        conda_path=$install_dir/bin
        export PATH=$conda_path:\$PATH

        conda_version=`conda --version`
       
}


#
# Variables
#

pyversion=3
python_version="3.6.10"
conda_version="4.9.2"
skip_install=$1
base_url='https://repo.anaconda.com/miniconda'
virtual_env=venv


#conda_file is only specified for use in messages below on Windows, as it is manual install, which must be done before running this script.
declare -A conda_file_map
conda_file_map[Linux]="Miniconda${pyversion}-py39_${conda_version}-Linux-x86_64.sh"


conda_file=${conda_file_map[${os_type}]}

#
# Installation of conda and its dependencies
#

if [ ${skip_install} != 'true' ];then

    conda_url=${base_url}/${conda_file}

    install_conda_for_linux


    #
    # Create Environment
    #

    output_formatted Creating new virtual environment: $virtual_env for python_version $python_version

    conda create -y -vv --name $virtual_env python=$python_version
   

Solution

  • Here's your bug:

    conda_path=$install_dir/bin
    export PATH=$conda_path:\$PATH
    

    Let's say install_dir=/path/to/install, and the starting value of PATH is PATH=/bin:/usr/bin:/usr/local/bin (which is how which sh finds /bin/sh or /usr/bin/sh).

    After you ran this command, because of the backslash, you don't have PATH=/path/to/install/bin:/bin:/usr/bin:/usr/local/bin (which is what you want), but instead you have PATH=/path/to/install/bin:$PATH; the backslash caused the literal string $PATH to be added to your variable, instead of the string that's contained therein.

    Thus, /bin and /usr/bin are no longer listed in your PATH variable, so which can't find them.


    To fix this, just make it:

    conda_path=$install_dir/bin
    PATH=$conda_path:$PATH
    

    The big fix is changing \$PATH to just $PATH -- but beyond that, you don't need the export (changes to variables that are already in the environment are automatically re-exported), and having it adds complexity for no good reason.