VSCode Python with Git bash:运行程序后,尝试运行Activate.ps1
我在settings.json中将VSCode集成终端设置为我的Git bash:VSCode Python with Git bash:运行程序后,尝试运行Activate.ps1,python,bash,visual-studio-code,python-venv,Python,Bash,Visual Studio Code,Python Venv,我在settings.json中将VSCode集成终端设置为我的Git bash: "terminal.integrated.automationShell.windows": "${env:LOCALAPPDATA}\\Programs\\Git\\bin\\bash.exe", 我已经选择了Python解释器,在我的虚拟环境中使用“Python:Select解释器”来选择解释器-当我打开它时,它显示: 当前:C:\work\u dir\pro
"terminal.integrated.automationShell.windows": "${env:LOCALAPPDATA}\\Programs\\Git\\bin\\bash.exe",
我已经选择了Python解释器,在我的虚拟环境中使用“Python:Select解释器”来选择解释器-当我打开它时,它显示:当前:C:\work\u dir\projdir\py\u env\venvdir\Scripts\python.exe 当转到调试器并启动程序(带或不带调试)时,bash终端将打开,并在终端中发出以下命令:
/usr/bin/env C:\\work_dir\\projdir\\py_env\\venvdir\\Scripts\\python.exe c:\\Users\\userid\\.vscode\\extensions\\ms-python.python-2020.9.111407\\pythonFiles\\lib\\python\\debugpy\\launcher 61892 -- c:\\work_dir\\projdir\\myscript.py -arg1 arg2
& C:/work_dir/projdir/py_env/venvdir/Scripts/Activate.ps1
(参数来自my launch.json)
然后,在脚本完成运行后,在终端中发出以下命令:
/usr/bin/env C:\\work_dir\\projdir\\py_env\\venvdir\\Scripts\\python.exe c:\\Users\\userid\\.vscode\\extensions\\ms-python.python-2020.9.111407\\pythonFiles\\lib\\python\\debugpy\\launcher 61892 -- c:\\work_dir\\projdir\\myscript.py -arg1 arg2
& C:/work_dir/projdir/py_env/venvdir/Scripts/Activate.ps1
我猜这是激活venv的PowerShell方式。当然,这会导致:
bash: syntax error near unexpected token `&'
脚本实际上运行良好
为什么在bash终端中运行脚本后,VSCode会在终端中发出命令,试图以PowerShell方式激活venv?这是双重的奇怪:它尝试在bash终端中使用PowerShell命令,并且它尝试在脚本之后而不是之前激活venv。除非手动将
python.terminal.activateEnvironment
设置更改为false,否则在执行.py文件之后会自动激活环境
您可以参考更多详细信息