简体   繁体   中英

VSCode Python with Git bash: After running program, tries to run Activate.ps1

I have the VSCode integrated terminal set to my Git bash, using this in settings.json:

    "terminal.integrated.automationShell.windows": "${env:LOCALAPPDATA}\\Programs\\Git\\bin\\bash.exe",

I have the Python interpreter selected, using "Python: Select Interpreter" to the interpreter in my virtual environment - when I bring it up, it shows:
Current: C:\\work_dir\\projdir\\py_env\\venvdir\\Scripts\\python.exe

When go to the debugger and start the program (with or without debugging), the bash terminal opens, and this command is issued in the terminal:

/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

(where the args come from my launch.json)

Then, after the script finishes running, this command is issued in the terminal:

& C:/work_dir/projdir/py_env/venvdir/Scripts/Activate.ps1

Which is the PowerShell way of activating the venv, I guess.
Which, of course, results in:

bash: syntax error near unexpected token `&'

The script actually runs fine.

Why is it that, after running the script in the bash terminal, VSCode issues a command in the terminal to try to activate the venv in a PowerShell way?
This is doubly weird: That it attempts a PowerShell command in a bash terminal, and that it attempts to activate the venv after and not before the script.

The environment is activated automatically after .py file being executed unless you manually change the python.terminal.activateEnvironment setting to false .

More detailed information you can refer to Environments and Terminal Windows

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM