[英]Command line doesn't use python from conda environment even though it's active, maybe problem in .bash_profile?
I've activated a conda environment and see it's active, but when I type "which python", I get "/usr/local/bin/python"
, instead of the python of the environment.我已经激活了一个 conda 环境并看到它处于活动状态,但是当我输入 "which python" 时,我得到"/usr/local/bin/python"
,而不是环境的 python 。 And I get Import errors for packages I know are installed.对于我知道已安装的软件包,我会收到导入错误。 I think the problem might be in .bash_profile
, but I don't know how to fix it.我认为问题可能出在.bash_profile
中,但我不知道如何解决。
I'm working on macOS.我正在使用 macOS。
How do I make sure that the command line uses the environment's python?如何确保命令行使用环境的 python?
Your PATH
environment variable probably doesn't contains the path to the python environment from conda.您的PATH
环境变量可能不包含从 conda 到 python 环境的路径。
Running export PATH="/path/to/conda/bin:$PATH"
or adding it to your ~/.bashrc
would probably solve your issue.运行export PATH="/path/to/conda/bin:$PATH"
或将其添加到您的~/.bashrc
可能会解决您的问题。
But there is a conda command that does it for you: conda init bash
但是有一个 conda 命令可以为您执行此操作: conda init bash
EDIT :编辑:
As mentionned in comment by @cel and also in the conda docs : It's better to use conda init
than explicitely editing PATH
by your own.正如@cel 在评论和 conda docs中提到的那样:使用conda init
比自己显式地编辑PATH
更好。
This will allow conda being less disruptive regarding other programs on your system.这将使 conda 对您系统上的其他程序的破坏性降低。
conda init
will add some more commands in your shell rc file to only modify PATH
when a conda environment is activated. conda init
将在您的 shell rc 文件中添加更多命令,以便仅在激活 conda 环境时修改PATH
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.