I have setup a virtual environment in my project folder using Command Palette: Python: Create Environment: .venv So whenever I open vs code in that folder it attempts to start the environment using .venv/Scripts/Activate.ps1 file which fails as running scripts is disabled for Powershell. So I want to switch to command prompt as default terminal and execute .venv/Scripts/Activate.bat by default instead.
I am able to switch default terminal to cmd but vs code still tries to run the .venv/Scripts/Activate.ps1 instead of .venv/Scripts/Activate.bat. How do I switch this default command from
& <file-path>/.venv/Scripts/Activate.ps1
to
<file-path>/.venv/Scripts/Activate.bat
Edit: So I want to be more clear about the issue...
The activate environment is set as true
And the default terminal is set as Command Prompt
"terminal.integrated.defaultProfile.windows": "Command Prompt"
When I have my project opened in vscode and create a new terminal whether cmd or powershell, vscode runs the proper command to run the virtual environment properly.
New terminal created by either +'plus' icon or View->Terminal
However, when I open the project using File->Open Folder or start vscode in that folder, then vscode automatically starts a terminal and tries to run the virtual environment. However, as the default terminal is cmd, Command Prompt starts but vscode tries to run the environment using the powershell command. I have to run the command manually or open a new terminal for it to run the proper command
I have no problem running the command again manually or creating a new terminal, but this error really bugs me. Hope this helps clear the problem.
When you choose a virtual environment interpreter, vscode will automatically activate the environment every time you build a new terminal. This is controlled by the following settings, and the default value is true.
"python.terminal.activateEnvironment": true,
The shell command that activates the virtual environment is based on your terminal automatic change:
PowerShell is & e:/workspace/py12/.venv/Scripts/Activate.ps1
CMD is e:/workspace/py12/.venv/Scripts/activate.bat
As for you every time you build a new terminal, you will create a new PowerShell or CMD, which is controlled by the following settings
"terminal.integrated.defaultProfile.windows": "PowerShell",