我正在开发ubuntu,为了一个小项目,我正在写一个.sh
(bash)文件,它将激活一个Conda环境并运行一个python文件。
#!/bin/sh
conda activate simple_python3.10
python3 code.py
当我运行bash文件时,conda会给我以下警告:
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
See 'conda init --help' for more information and options.
IMPORTANT: You may need to close and restart your shell after running 'conda init'.
现在我不知道该怎么办,我用了conda init bash
,但是没有用,我把conda init bash
加到文件里,但是没有用,这个警告又出现了,我也重新启动了电脑,但是没有用,你能告诉我该怎么办吗?
pidoss.只是为了这个案例。这是我运行conda init bash
后得到的:
no change /home/p2mohsen/anaconda3/condabin/conda
no change /home/p2mohsen/anaconda3/bin/conda
no change /home/p2mohsen/anaconda3/bin/conda-env
no change /home/p2mohsen/anaconda3/bin/activate
no change /home/p2mohsen/anaconda3/bin/deactivate
no change /home/p2mohsen/anaconda3/etc/profile.d/conda.sh
no change /home/p2mohsen/anaconda3/etc/fish/conf.d/conda.fish
no change /home/p2mohsen/anaconda3/shell/condabin/Conda.psm1
no change /home/p2mohsen/anaconda3/shell/condabin/conda-hook.ps1
no change /home/p2mohsen/anaconda3/lib/python3.9/site-packages/xontrib/conda.xsh
no change /home/p2mohsen/anaconda3/etc/profile.d/conda.csh
no change /home/p2mohsen/.bashrc
No action taken.
1条答案
按热度按时间mwg9r5ms1#
看起来你不能只在bash文件中执行
conda activate
。你应该在调用它之前添加eval "$(conda shell.bash hook)"
行。所以我把我的
.sh
文件改成这样,它工作了: