我只是希望我的集成终端在使用 vscode ssh-remote 时尽可能与我的普通终端相似。
我不明白为什么 vscode 集成终端似乎在挑选哪些东西放在我的 PATH 中以及哪些东西不放。
我在 Linux 系统上使用 Visual Studio Code 的集成终端时遇到问题。尽管终端显然采购了我的
.bashrc
文件(通过 echo
语句确认),但它似乎有选择地应用配置。具体来说,它尊重对 Poetry 所做的 PATH
修改,但忽略 conda activate
命令。
.bashrc
的相关部分:
# Setting up Poetry
export VENV_PATH=$HOME/.virtualenvs/venv_for_poetry
export PATH="$VENV_PATH/bin:$PATH"
# Conda initialization
__conda_setup="$('$HOME/miniconda/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "$HOME/miniconda/etc/profile.d/conda.sh" ]; then
. "$HOME/miniconda/etc/profile.d/conda.sh"
else
export PATH="$HOME/miniconda/bin:$PATH"
fi
fi
unset __conda_setup
# Activating conda environment
conda activate snap_cluster_setup_py311
症状:
PATH
已正确修改为包含 Poetry 环境。snap_cluster_setup_py311
未激活,即使 echo
语句确认行 conda activate snap_cluster_setup_py311
已执行。我尝试过的:
.bashrc
命令来确保 echo
的来源。settings.json
以显式使用 bash 和 source .bashrc
:
"terminal.integrated.profiles.linux": {
"bash": {
"path": "/bin/bash",
"args": ["-i"]
}
},
"terminal.integrated.defaultProfile.linux": "bash"
terminal.integrated.inheritEnv
设置(true 和 false)进行测试。.bashrc
,观察到了相同的行为。 "workbench.startupEditor": "none",
"terminal.integrated.profiles.linux": {
"bash": {
"path": "/bin/bash",
"args": ["-i", "-c", "exec bash --rcfile ~/.bashrc"]
}
},
"terminal.integrated.defaultProfile.linux": "bash"
这不起作用,但它确实回显了两次 NEW :
NEW
NEW
(snap_cluster_setup_py311) brando9@ampere1~ $ echo $PATH | tr ':' '\n'
/lfs/ampere1/0/brando9/.virtualenvs/venv_for_poetry/bin
/lfs/ampere1/0/brando9/.elan/bin
/afs/cs/software/bin
/lfs/ampere1/0/brando9/.virtualenvs/venv_for_poetry/bin
/lfs/ampere1/0/brando9/.elan/bin
/afs/cs/software/bin
/lfs/ampere1/0/brando9/.vscode-server-insiders/cli/servers/Insiders-5ae5a741bdb676abb667fd4896dc2a40e313db3a/server/bin/remote-cli
/lfs/ampere1/0/brando9/miniconda/envs/snap_cluster_setup_py311/bin
/lfs/ampere1/0/brando9/miniconda/condabin
/lfs/ampere1/0/brando9/.virtualenvs/venv_for_poetry/bin
/lfs/ampere1/0/brando9/.elan/bin
/usr/kerberos/sbin
/usr/kerberos/bin
/afs/cs/software/sbin
/afs/cs/software/bin
/usr/local/sbin
/usr/local/bin
/usr/sbin
/usr/bin
/sbin
/bin
/usr/games
/usr/local/games
/snap/bin
/opt/puppetlabs/bin
我不明白为什么 vscode 集成终端似乎在挑选哪些东西放在我的 PATH 中,哪些东西不放。
还有我的初始用户 vscode settings.json:
{
"workbench.colorTheme": "Visual Studio Dark",
"editor.inlineSuggest.enabled": true,
"workbench.colorCustomizations": {},
"explorer.confirmDragAndDrop": false,
"terminal.integrated.enableMultiLinePasteWarning": false,
"[python]": {
"diffEditor.ignoreTrimWhitespace": false,
"editor.formatOnType": true,
"editor.wordBasedSuggestions": "off"
},
"github.copilot.enable": {
"*": false,
"plaintext": false,
"markdown": false,
"scminput": false,
"lean4": true,
"python": true
},
"terminal.integrated.inheritEnv": false,
"window.zoomLevel": -1,
"python.analysis.fixAll": [
],
"debug.focusEditorOnBreak": false,
"accessibility.signals.lineHasInlineSuggestion": {
"sound": "off"
},
"workbench.startupEditor": "none"
}
问题: 为什么 VSCode 的终端应用 Poetry 的 PATH 更改但不激活 Conda 环境?是什么导致了
.bashrc
设置的选择性应用,以及如何确保 Conda 环境正确激活?
交叉发布:https://discord.com/channels/470167643710816277/1107255712628871229/1236121346384072854
黑客解决方案。如果子字符串路径已经存在,我告诉我的
.bashrc
不要编辑我的PATH
:
...
# Check if the CS software directory is already in the PATH. If not, prepend it to access CS software tools first.
if [[ ":$PATH:" != *":/afs/cs/software/bin:"* ]]; then
echo "Adding CS software tools to PATH"
export PATH="/afs/cs/software/bin:$PATH"
fi
...
# Check if the Elan tools directory is already in the PATH. If not, prepend it to ensure Elan tools are prioritized.
if [[ ":$PATH:" != *":$HOME/.elan/bin:"* ]]; then
echo "Adding Elan tools to PATH"
export PATH="$HOME/.elan/bin:$PATH"
fi
...
# Check if the Poetry virtual environment path is already in the PATH. If not, prepend it to ensure the Poetry environment is prioritized.
if [[ ":$PATH:" != *":$VENV_PATH/bin:"* ]]; then
echo "adding virtualenvs to path"
export PATH="$VENV_PATH/bin:$PATH"
fi
...
conda activate snap_cluster_setup_py311
这似乎对我有用:
(snap_cluster_setup_py311) brando9@ampere1~ $ echo $PATH | tr ":" "\n"
/lfs/ampere1/0/brando9/.vscode-server-insiders/cli/servers/Insiders-5ae5a741bdb676abb667fd4896dc2a40e313db3a/server/bin/remote-cli
/lfs/ampere1/0/brando9/miniconda/envs/snap_cluster_setup_py311/bin
/lfs/ampere1/0/brando9/miniconda/condabin
/lfs/ampere1/0/brando9/.virtualenvs/venv_for_poetry/bin
/lfs/ampere1/0/brando9/.elan/bin
/usr/kerberos/sbin
/usr/kerberos/bin
/afs/cs/software/sbin
/afs/cs/software/bin
/usr/local/sbin
/usr/local/bin
/usr/sbin
/usr/bin
/sbin
/bin
/usr/games
/usr/local/games
/snap/bin
/opt/puppetlabs/bin
虽然我真的不认为这是一个好的解决方案。 VScode 不应该挑选如何运行我的
.bashrc
。如果它再次运行,那么 所有内容都应该按正确的顺序添加,尤其是我的 conda env 。但我想它并没有做到这一点。否则调试器将无法工作等等。