0

I am running Visual Studio Code in windows 10 environment.

I am trying to set up VsCode to activate venv when I create a new terminal or I open VsCode.

Here is some settings in .vscode/settings.json

    "python.pythonPath": "venv\\Scripts\\python.exe",
    "python.defaultInterpreterPath": "venv\\Scripts\\python.exe",
    "python.terminal.activateEnvironment": true,
    "python.terminal.activateEnvInCurrentTerminal": true,

The problem is it runs

c:/abs/path/to/project/venv/Scripts/Activate.ps1

that returns

& was unexpected at this time.

instead of

c:/abs/path/to/project/venv/Scripts/Activate

that activates the virtual environment

I am using company laptop with limited access so I can not have access to registry and fix it.

So, the question is, how to make VsCode use

c:\abs\path\to\project\venv\Scripts\Activate

Note: if I run c:/abs/path/to/project/venv/Scripts/Activate it activates venv for me

Amin Ba
  • 1,603
  • 1
  • 13
  • 38

1 Answers1

0

Is the venv a conda environment? If so, please note:

Note: conda environments cannot be automatically activated in the integrated terminal if PowerShell is set as the integrated shell. See Integrated terminal - Configuration for how to change the shell.

Source: https://code.visualstudio.com/docs/python/environments

You'll need to set your default integrated terminal to use command prompt -- please see: https://code.visualstudio.com/docs/editor/integrated-terminal#_terminal-profiles

E.g., add/replace this in your settings.json:

"terminal.integrated.defaultProfile.windows": "Command Prompt",
...
user18337734
  • 31
  • 1
  • 5