If you’re like me and enjoy using different IDEs, but don’t enjoy errors, you will need to go through some extra configuration steps in order to allow use of the Anaconda, or “Conda” from within VS Code’s default terminal, PowerShell. This article assumes you already have Anaconda and VS Code installed.
This problem will generally first arise when choosing “conda” as your Python interpreter in VS Code, after which you will be greeted with this unfriendly bit of red text:
The first thing we will need to do is add the anaconda3 and anaconda3\Scripts directories to our Windows PATH variable, which defines where executables are stored on your system. We’ll find this by opening up a Windows search, typing in “path”, and clicking on “Edit the system environment variables”
We’ll then click “Environment Variables…”
We’ll then highlight “Path”, and click “Edit”
Click “New”, and add the directory where you have Anaconda installed. In my case, it was in my user folder, “C:\Users\<username>\anaconda3” but in other cases, it may be installed in the root directory. After you have added that entry to the list, you will also want to add the “\Scripts” folder, which should be in your Anaconda folder as well. “C:\Users\<username>\anaconda3\Scripts”. After you’ve added both of those, click “OK”.
Now open a PowerShell window, being sure to run it as adminstrator. In my case, I’ll be using Windows Terminal for this. This could also be done using the terminal in VS Code, but it isn’t necessary.
Execute the following commands:
Set-ExecutionPolicy RemoteSigned conda init powershell
If you have Windows Protected Folder Access enabled (which I recommend!), this operation will likely throw an error, saying “Operation failed”. This is due to Protected Folder Access preventing changes to the Documents\WindowsPowerShell folder.
The error should also prompt a notification from Windows, notifying you of the prevented change. Click that notification, taking you to “Protection history”, click the most recent event, “Actions”, and then “Allow on device”. You may just be able to run the command in PowerShell again, but to be safe, I would close out your current terminal and open a new one before rerunning the commands.
Anaconda should now be available for use within VS Code’s default terminal, PowerShell. We can verify this by checking Anaconda’s version from within a terminal.