【发布时间】:2021-06-21 17:18:06
【问题描述】:
我有一个 bash 脚本,我将在其中创建 conda 虚拟环境并将软件包安装到其中。 目前我们在我的虚拟环境中使用 conda 4.5.12 和 python 3.6。
我正在尝试使用 python 3.6 将 conda 版本升级到 4.9.2。
conda --version
4.9.2
这是我在脚本中使用的命令
conda create -y --name virtual_env python=3.6
这在下载和提取包步骤期间运行并失败。以下是错误报告
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!
()
请高手帮忙。
添加脚本简介
#!/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
【问题讨论】:
-
听起来这是一个 BASH 问题,而不是 Python 问题(Python 只是 Conda 附带的)。请包括你的 BASH 脚本的 shebang 和你用来运行脚本的确切命令。
-
@merv,
conda是 shell 函数还是带有自己的 shebang 的可执行文件?如果是后者,则 shell invokingconda的身份无关紧要。 -
无论如何——根据github.com/conda/conda/blob/…,这是由既不包含
bash也不包含sh的PATH 引起的。 -
@saravankumar,你能提供足够的minimal reproducible example 让其他人自己看到问题吗?也许周围的代码会改变 PATH(无论是有意还是无意),也许你是在一个软件负载最小的 Docker 容器中运行它——无论环境是什么,都应该包含足够的细节让其他人看到问题问题本身。
-
@saravankumar,再次检查失败时 PATH 的设置方式。例如,
python -i yourscript将在脚本退出时将您带到交互式 shell,因此您可以从那里检查os.environ['PATH']。