Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to activate conda environment in vs code

I created a virtual environment using miniconda. I'm using Visual Studio Code with Mask rcnn, but I can't start the virtual environment in Visual Studio Code, I get an error.Sevinirim

enter image description here

like image 221
Mehmet Kurt Avatar asked Nov 27 '25 03:11

Mehmet Kurt


2 Answers

Please read this: https://py-vscode.readthedocs.io/en/latest/files/venv.html#selecting-switching-between-the-environments-in-vs-code

Press ctrl+shift+P to open VS Code’s command palette.

Type interpreter in the search box. And select the Python: Select Interpreter option. You should see a list of all the available (both conda and virtual environments are shown) python environments. You should also see your recently created myenv environment there. Toggle and select your environment and you are good to go.

After ctrl+shift+P

enter image description here

Select conda env from a list

enter image description here

like image 140
Be Chiller Too Avatar answered Nov 28 '25 17:11

Be Chiller Too


You are getting this error because conda activate env-name won't work in a VS Code Powershell (PS) terminal. When opening terminal in Windows VS Code, this is typically the default terminal shell.

A couple solutions:

  1. Open a new VS Code terminal session that uses Command Prompt (cmd) as its shell - see this answer
  2. Change your default shell to cmd (instructions below)

From VS Code doc's: Conda environments can't be automatically activated in the VS Code Integrated Terminal if the default shell is set to PowerShell. To change the shell, see Integrated terminal - Terminal profiles.

like image 25
Wilson Sauthoff Avatar answered Nov 28 '25 17:11

Wilson Sauthoff