无法使用生成的 tmux 窗口激活 conda 环境



我有一个工作流,可以生成一个新的tmux窗口并在该新窗口中执行命令。

正在执行的命令是需要特定conda环境的 Python 应用程序。

我刚刚意识到,一旦调用了该新窗口,它就会使用默认的conda环境进行调用。当我尝试使用conda activate myEnv命令调用tmux窗口时,出现错误。

这是我在测试中使用的命令:

tmux new-window -n:mywindow 'echo "__START__"; conda activate py37; echo "___END___"; sleep 5'

以下是我在调用的tmux窗口中遇到的错误:

__START__
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'.

___END___

有什么想法吗?

更多详情:

conda 4.7.12
Linux (Ubuntu 18.04)
Python3.7
tmux 3.0a
vim-dispatch (the plugin that invokes a new pane to run my app)

conda 的东西都在你正在使用的 shell 中,所以无论是 bash 还是其他东西,你都需要确保你已经运行了conda init,并且CONDA_DEFAULT_ENV环境变量存在。我这里有一个半相关的答案,可能会帮助某人 - https://stackoverflow.com/a/66312869/8490364

我最近遇到了完全相同的问题。就我而言,我已经在tmux之外运行了conda init.但这并没有帮助解决问题。因此,我没有直接解决它,而是找到了解决方法。

基本上,激活 conda 并不是运行需要在该 conda 环境中安装包的 Python 应用程序的必要条件。假设当你在tmux之外运行conda activate py37 && which python3时,它会给你~/miniconda3/env/py37/bin/python3。然后在tmux中,你可以只用~/miniconda3/env/py37/bin/python3而不是裸python3运行Python应用程序。我知道它并不完美,但它有效。

最新更新