python - Conda 命令在命令提示符下工作,但不在 bash 脚本中
问题描述
只要我只是通过 linux 终端(bash shell)使用它,我的 anaconda(4.5.4)就可以正常工作。但是,在 bash 脚本中运行 conda 命令根本不起作用。
脚本 test.sh 包含以下几行:
#!/bin/bash
conda --version
conda activate env
现在,运行bash test.sh
导致错误
test.sh: line 2: conda: command not found
test.sh: line 3: conda: command not found
按照 anaconda 版本 > 4.4 的建议,我的 .bashrc 不包含
export PATH="/opt/anaconda/bin:$PATH",
但
. /opt/anaconda/etc/profile.d/conda.sh
谢谢你。
解决方案
感谢@darthbith 的评论,我解决了这个问题。
由于conda
是一个 bash 函数并且 bash 函数不能传播到独立的 shell(例如通过执行 bash 脚本打开),因此必须添加该行
source /opt/anaconda/etc/profile.d/conda.sh
在调用 conda 命令之前到 bash 脚本。否则 bash 将不知道 conda。
推荐阅读
- sql - tsrange计算时间间隔?
- python - 使用 Django 从服务器获取多张图片
- oracle12c - Liquibase 不支持的 major.minor 版本 51.0
- css - 使用带有 rem = 10px 的引导程序的问题
- python - 将字典中的所有值设为小写
- vb.net - VB.NET 面板无法在 groupbox 内正确显示
- javascript - 在 NextJS 中显示多条 JSON 记录
- javascript - 在 a 中写入一个元素
- 带有 Javascript 的元素
- python - 在 Scikit-Learn 中获得线性回归的大交叉验证分数
- css - 如何用 CSS 制作鸡蛋形状