gpt4 book ai didi

python - Makefile 无法使用 `conda activate`

转载 作者:行者123 更新时间:2023-12-02 03:57:36 26 4
gpt4 key购买 nike

我需要在 makefile 中激活 conda 环境才能运行一些 python 脚本,但是,每当我尝试运行 conda activate env_name 时,我都会收到以下消息:

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 ". /Users/MY_USERNAME/anaconda3/etc/profile.d/conda.sh" >> ~/.bash_profile

or, for all users, enable conda with

$ sudo ln -s /Users/MY_USERNAME/anaconda3/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" >> ~/.bash_profile

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

export PATH="/Users/MY_USERNAME/anaconda3/bin:$PATH"

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

我尝试通过在顶部添加 SHELL :=/bin/zsh 来更改 makefile 的 shell,但这并不能解决问题。此外,我需要这个 makefile 才能使用计算机的默认 shell 运行(我的一些队友使用 zsh,其他人使用 bash)。似乎无论我做什么,我都无法让 conda activate 在 makefile 中工作。

我该怎么做才能让它工作,或者这是不可能的?

最佳答案

经过一番搜索后,我想出了将此模式添加到我的 Makefile 中以使 conda activate 工作。其他人也许能够简化。

# Need to specify bash in order for conda activate to work.
SHELL=/bin/bash
# Note that the extra activate is needed to ensure that the activate floats env to the front of PATH
CONDA_ACTIVATE=source $$(conda info --base)/etc/profile.d/conda.sh ; conda activate ; conda activate

py3build:
($(CONDA_ACTIVATE) py3.6 ; python setup.py build )

关于python - Makefile 无法使用 `conda activate`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53382383/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com