![tmux 導致 anaconda 使用不同的 python 來源](https://rvso.com/image/112014/tmux%20%E5%B0%8E%E8%87%B4%20anaconda%20%E4%BD%BF%E7%94%A8%E4%B8%8D%E5%90%8C%E7%9A%84%20python%20%E4%BE%86%E6%BA%90.png)
好的,我在 anaconda 環境中運行了 which python.我明白了
/home/comp/anaconda3/envs/env1/bin/python
現在,如果我啟動 tmux,然後運行 source activate env1,然後運行哪個 python,我得到
/home/comp/anaconda3/bin/python
即使我確實激活了我的環境。如何讓 anaconda 在 tmux 中看到相同的路徑?
答案1
解決方案似乎是停用 conda 環境,然後啟動 tmux,然後重新啟動 tmux 內的環境。
答案2
我遇到了同樣的問題,但我真的不喜歡任何解決方案,因為它們涉及每次加載到tmux
.因此,我將以下內容添加到我的.tmux.conf
:
重要編輯:此程式碼對我有用,因為我目前正在執行 zsh shell,這是儲存我的設定的位置。您的標準 shell 可能有所不同,要查找您的 shell 位置,請使用該命令echo "$SHELL"
並將我的答案中的 替換/bin/zsh
為您自己的 shell 路徑。
set -g default-command "/bin/zsh"
完成後,只需為您的.tmux.conf
文件提供資源即可啟動變更。這應該允許tmux
加載您在.bash_profile
Conda 中擁有的任何設定。
答案3
此行為是由 TMux 來源~/.profile
而非~/.bashrc
.我的~/.profile
是這樣的:
# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
PATH="$HOME/.local/bin:$PATH"
fi
你可以看到第一的 ~/.bashrc
來源和然後 ~/bin
並且~/.local/bin
是前置的。正如我自己經歷的那樣,這會導致conda
打嗝。
解決方案是註解掉 中操作 PATH 的兩個區塊~/.profile
。
編輯(2019/09/24):更好的方法似乎是配置 TMux,使其不會產生登入 shell,而只是產生一個普通的 shell。請參閱連結問題的答案。
答案4
啟動 Tmux 會話後(沒有 conda 具有任何活動環境),我會發生以下情況。
當我第一次在 Tmux 會話中執行操作時:
conda activate myEnv
我明白了
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'.
如果我這樣做:
source deactivate
conda activate myEnv
一切都很好。which python
指向正確的路徑。