命令行不使用 conda 环境中的 python,即使它处于活动状态,也可能是 .bash_profile 中的问题?
Command line doesn't use python from conda environment even though it's active, maybe problem in .bash_profile?
我已经激活了一个 conda 环境并看到它处于活动状态,但是当我键入 "which python" 时,我得到的是 "/usr/local/bin/python"
,而不是环境的 python。对于我知道已安装的包,我收到导入错误。我认为问题可能出在 .bash_profile
,但我不知道如何解决它。
我正在使用 macOS。
如何确保命令行使用环境的 python?
您的 PATH
环境变量可能不包含从 conda 到 python 环境的路径。
运行 export PATH="/path/to/conda/bin:$PATH"
或将其添加到您的 ~/.bashrc
可能会解决您的问题。
但是有一个 conda 命令可以为您完成:conda init bash
编辑:
正如@cel 在评论中以及 conda docs 中提到的那样:使用 conda init
比自己明确编辑 PATH
更好。
这将减少 conda 对您系统上其他程序的干扰。
conda init
将在您的 shell rc 文件中添加更多命令,以便仅在激活 conda 环境时修改 PATH
。
我已经激活了一个 conda 环境并看到它处于活动状态,但是当我键入 "which python" 时,我得到的是 "/usr/local/bin/python"
,而不是环境的 python。对于我知道已安装的包,我收到导入错误。我认为问题可能出在 .bash_profile
,但我不知道如何解决它。
我正在使用 macOS。
如何确保命令行使用环境的 python?
您的 PATH
环境变量可能不包含从 conda 到 python 环境的路径。
运行 export PATH="/path/to/conda/bin:$PATH"
或将其添加到您的 ~/.bashrc
可能会解决您的问题。
但是有一个 conda 命令可以为您完成:conda init bash
编辑:
正如@cel 在评论中以及 conda docs 中提到的那样:使用 conda init
比自己明确编辑 PATH
更好。
这将减少 conda 对您系统上其他程序的干扰。
conda init
将在您的 shell rc 文件中添加更多命令,以便仅在激活 conda 环境时修改 PATH
。