【发布时间】:2021-12-27 20:30:16
【问题描述】:
我已经尝试了我在 SO 上看到的所有内容以使其正常工作,但到目前为止一切都失败了。使用 macOS Big Sur 11.6,在终端中 bash(不是 zsh)。
我正在尝试创建一个安装文件并使用sh setup.sh 执行,它将设置环境,安装python,然后激活它。没有什么花哨。手动操作可以正常工作,但是一旦我将其放入 shell 脚本中,它将无法正常工作。我在一个空的项目文件夹中运行这个脚本。
当前脚本:
conda create -n MASTER python=3.8.5 -y
conda activate MASTER
是的,开始就是这么简单。我注释掉了其他 pip 安装,直到它正常工作。
我尝试运行:bash -i setup.sh,但它仍然没有激活。我没有收到任何错误,但我仍然卡在(base)。
我尝试在脚本开头和/或激活之前使用 source:source /opt/anaconda3/etc/profile.d/conda.sh,但仍然无法正常工作。再次没有错误,但卡在(base)。
我尝试在脚本开始和尝试激活环境之前使用:eval $(conda shell.bash hook),但它失败了。这次我得到了错误:
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run
$ conda init <SHELL_NAME>
Currently supported shells are:
- bash
- fish
- tcsh
- xonsh
- zsh
- powershell
但如果我运行conda init bash(在终端或脚本本身),它会输出:
no change /opt/anaconda3/condabin/conda
no change /opt/anaconda3/bin/conda
no change /opt/anaconda3/bin/conda-env
no change /opt/anaconda3/bin/activate
no change /opt/anaconda3/bin/deactivate
no change /opt/anaconda3/etc/profile.d/conda.sh
no change /opt/anaconda3/etc/fish/conf.d/conda.fish
no change /opt/anaconda3/shell/condabin/Conda.psm1
no change /opt/anaconda3/shell/condabin/conda-hook.ps1
no change /opt/anaconda3/lib/python3.8/site-packages/xontrib/conda.xsh
no change /opt/anaconda3/etc/profile.d/conda.csh
no change /Users/liquidRock/.bash_profile
No action taken.
我尝试做/opt/anaconda3/bin/conda activate MASTER,这也提示我做conda init bash。
为了以防万一,甚至尝试将#!/bin/bash 添加到文件顶部,但没有骰子。
【问题讨论】:
-
为什么不获取脚本?执行它不可能改变你的环境
-
-
可能是因为我只做了 4 天的事情:P 好吧,我该死的,它起作用了:
source setup.sh在终端中。谢谢。 Anaconda 对我的.bashrc没有添加任何内容。这一切都在.bash_profile。将所有 conda 代码从中复制到脚本中,仍然不起作用。它没有激活。 ??????????♂️ -
执行一个脚本不能修改你的shell环境,不管它里面做了什么,因为它是在它自己的环境(子shell)中执行的。内置的
source意味着read and execute commands from a file in the current shell environment
标签: python bash macos shell anaconda