powershell - VS Code集成终端尝试激活python虚拟环境时自动适配shell类型
问题描述
前言:git bash 已经可以工作了
我按照这些说明进行操作,一旦我打开 VS-Code 项目工作区,右下角的 python 解释器总是被正确预选:
此外,以下设置在我的本地处于活动状态.vscode/settings.json
:
"python.terminal.activateEnvironment": true
当我git bash shell
默认打开一个新终端时,或者在打开的终端中打开另一个 git bash shell 时,venv 的来源是正确的:
username@hd1pcms0347 MINGW64 ~/Projects/proj
$ source c:/Users/username/Projects/proj-venv/Scripts/activate
(proj-venv)
username@hd1pcms0347 MINGW64 ~/Projects/proj
到目前为止一切都很好,但现在是痛点:
每隔一段时间,我就喜欢打开不同的外壳类型,尤其是PowerShell
.
不幸的是,当我在 VS-Code 集成终端中将 PowerShell 作为新 shell 打开时,它会执行与source ...
git bash shell 中相同的 - 命令,这将不起作用:
source c:/Users/username/Projects/proj-venv/Scripts/activate
source : The term 'source' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the
path is correct and try again.
At line:1 char:1
+ source c:/Users/username/Projects/proj-venv/Scripts/activate
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (source:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
所以,问题是,是否有一种方法可以让 VS-Code 识别刚刚打开的终端类型,以便相应地调整这个 venv-source 命令。
解决方案
推荐阅读
- java-9 - 如何在 Windows 系统上使用 NASA 的 panoply?
- powershell - Powershell:对象中的对象 - 提取属性值(并导出到 CSV) - OneNoteUtilitiesGraph
- tensorflow - 导入 TensorFlow 会阻止其他库的正常运行
- reactjs - 反应取消 clearTimeout 在 useEffect 上无法正常工作
- ios - ld: 找不到 -lReact-hermes 的库
- c++ - 这个递归解决方案的时间复杂度是多少
- javascript - 如何以相对位置将绝对元素定位在body的特定坐标中?
- snowflake-cloud-data-platform - 在 Snowflake 中创建和管理用户和角色的推荐角色
- react-native - 无法转换 react-native-reanimated-66-jsc.aar(自我回答的问题)
- visual-studio - IntelliJ 是否有像 Visual Studio 这样的行移动快捷方式?