有没有办法在VS Code 1.56中自动激活环境?
之前,我使用以下工作空间设置在终端中自动激活环境:
"terminal.integrated.shellArgs.linux": [
"/path/to/activate.sh",
],它在启动后立即激活了环境。
这些设置在最新版本中已弃用:
https://code.visualstudio.com/updates/v1_56#_terminal
我尝试使用新的设置:
"terminal.integrated.profiles.linux": {
"bash": {
"path": "bash",
"args": [
"/path/to/activate.sh",
],
},
},不幸的是,它只适用于新终端,或者当我在VS代码完全加载后启动并切换到终端后打开了一个不同的选项卡。
有没有办法马上激活环境?
发布于 2021-05-18 01:25:51
这在我的settings.json中起作用了
"terminal.integrated.defaultProfile.linux": "zsh",
"terminal.integrated.profiles.linux": {
"bash": {
"path": "bash"
},
"zsh": {
"path": "zsh",
"args": ["-l"]
},
"fish": {
"path": "fish"
},
"tmux": {
"path": "tmux",
"icon": "terminal-tmux"
},
"pwsh": {
"path": "pwsh",
"icon": "terminal-powershell"
}
},确保将"args“键添加到您正在使用的shell中。在我的例子中,它是zsh,所以我添加了"-l“参数来加载我的.zprofile脚本。
希望这对您有所帮助!:)
有关终端配置文件的更多详细信息,请查看:https://code.visualstudio.com/updates/v1_55#_terminal-profiles
发布于 2021-05-22 01:13:35
当您打开项目或打开另一个终端时,要在集成终端上“自动”激活python venv并加载.env文件,请确保您设置了以下设置:
用户设置界面
Python: Env File
${workspaceFolder}/.env
Python>Terminal: Activate Env In Current Terminal
True
Python>Terminal: Activate Environment
True确保venv位于项目文件夹的根目录下,例如:
./MyProject (workspaceFolder)
./MyProject/venv
./MyProject/.env
./MyProject/djangoproject
./MyProject/djangoproject/[djangoapps]
./MyProject/djangoproject/manage.py
./MyProject/setup.py
./MyProject/requirements.txt如果失败,请尝试将工作空间设置为:
"python.pythonPath": "./venv/bin/python",
"python.terminal.activateEnvInCurrentTerminal": true,作为参考,下面是我当前的设置:
用户settings.json:
{
"python.sortImports.path": "./venv/bin/python",
"terminal.integrated.defaultProfile.linux": "zsh",
"python.terminal.activateEnvInCurrentTerminal": true,
"terminal.integrated.profiles.linux": {
"bash": {
"path": "bash"
},
"zsh": {
"path": "zsh",
"args": ["-l"]
},
"fish": {
"path": "fish"
},
"tmux": {
"path": "tmux",
"icon": "terminal-tmux"
},
"pwsh": {
"path": "pwsh",
"icon": "terminal-powershell"
}
},
"terminal.integrated.profiles.osx": {
"bash": {
"path": "bash"
},
"zsh": {
"path": "zsh",
"args": ["-l"]
},
"fish": {
"path": "fish"
},
"tmux": {
"path": "tmux",
"icon": "terminal-tmux"
},
"pwsh": {
"path": "pwsh",
"icon": "terminal-powershell"
}
},
}工作区setting.json:
{
"python.pythonPath": "./venv/bin/python",
"python.terminal.activateEnvInCurrentTerminal": true,
}https://stackoverflow.com/questions/67530195
复制相似问题