【问题标题】:.bashrc not activating conda.bashrc 没有激活 conda
【发布时间】:2021-11-10 11:55:47
【问题描述】:

我有 conda 4.5.11,我正在尝试运行一个 bash 脚本来激活我创建的 coda 环境。但是它一直告诉我:


CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
If your shell is Bash or a Bourne variant, enable conda for the current user with

    $ echo ". /nvme/h/buildsets/eb_cyclone/software/Anaconda3/5.3.0/etc/profile.d/conda.sh" >> ~/.bashrc

or, for all users, enable conda with

    $ sudo ln -s /nvme/h/buildsets/eb_cyclone/software/Anaconda3/5.3.0/etc/profile.d/conda.sh /etc/profile.d/conda.sh

The options above will permanently enable the 'conda' command, but they do NOT
put conda's base (root) environment on PATH.  To do so, run

    $ conda activate

in your terminal, or to put the base environment on PATH permanently, run

    $ echo "conda activate" >> ~/.bashrc

Previous to conda 4.4, the recommended way to activate conda was to modify PATH in
your ~/.bashrc file.  You should manually remove the line that looks like

    export PATH="/nvme/h/buildsets/eb_cyclone/software/Anaconda3/5.3.0/bin:$PATH"

^^^ The above line should NO LONGER be in your ~/.bashrc file! ^^^


Traceback (most recent call last):
  File "main_foml_trans.py", line 7, in <module>
    import tensorflow as tf
ModuleNotFoundError: No module named 'tensorflow'

然而,这就是我的.bashrc 的样子:

# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
    . /etc/bashrc
fi

# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=

# User specific aliases and functions
export DATA_p077=/onyx/data/p077
export DATA_p078=/onyx/data/p078
. /nvme/h/buildsets/eb_cyclone/software/Anaconda3/5.3.0/etc/profile.d/conda.sh
conda activate

我不确定发生了什么以及如何解决此错误,尽管从消息中很明显,但一切都在那里,这是一种奇怪的行为。

这是我正在使用的 bash 脚本:

#!/usr/bin/env bash
#SBATCH --job-name=fgpu
#SBATCH --account=p077
#SBATCH --partition=gpu
#SBATCH --nodes=1
#SBATCH --gres=gpu:1
#SBATCH --gpus=1
#SBATCH --mem=16000
#SBATCH --time=0-01:00:00

module load Anaconda3/5.3.0   
conda activate tensorflow-dementia

jobid=$SLURM_JOBID

python main_foml_trans.py > job${jobid}.txt

【问题讨论】:

    标签: python bash anaconda conda


    【解决方案1】:

    除非 shebang 是 #!/usr/bin/env bash -l,否则 SLURM 脚本不会获取 .bashrc。另外,我不会在.bashrc 中包含conda activate,除非您绝对希望默认激活 base 环境 - 这不是必需的。

    顺便说一句,如果您使用较新的 Conda,那么您可以使用:

    conda run -n tensorflow-dementia python main_foml_trans.py > job${jobid}.txt
    

    无需激活。一般来说,不使用系统级 Anaconda 并为自己安装 Mambaforge 可能会有更好的体验。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-08-30
      • 1970-01-01
      • 2016-06-08
      • 2020-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多