我有一个工作流程,可以生成一个新的
tmux
窗口并在该新窗口中执行命令。
正在执行的命令是一个Python应用程序,需要特定的
conda
环境。
我刚刚意识到,一旦调用该新窗口,就会使用默认的
conda
环境来调用它。当我尝试使用 tmux
命令调用 conda activate myEnv
窗口时,出现错误。
这是我在测试中使用的命令:
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
我最近遇到了完全相同的问题。就我而言,我已经在
conda init
外面跑步了 tmux
。但这并没有帮助解决问题。因此,我没有直接解决它,而是找到了解决方法。
基本上,激活 conda 并不是运行需要在该 conda 环境中安装包的 Python 应用程序的必要条件。假设当您在
conda activate py37 && which python3
之外运行 tmux
时,它会给您 ~/miniconda3/env/py37/bin/python3
。然后在 tmux
中,您可以使用 ~/miniconda3/env/py37/bin/python3
而不是裸露的 python3
来运行 Python 应用程序。我知道它并不完美,但它有效。