VS Code Python Interactive Window Cannot find Conda Env

Question:

Everytime I try to execute my python code to the Python Interactive Window I get the below error…

Executing code failed : Error: Activating Python 3.7.3 64-bit ('base': conda) to run Jupyter failed with Error: 
Command failed: "H:/My Documents/Continuum/anaconda3/Scripts/activate" && conda activate base && 
echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python 
c:/Users/paul.victor/.vscode/extensions/ms-python.python-2019.11.50794/pythonFiles/printEnvVariables.py python: 
can't open file 'H:My': [Errno 2] No such file or directory .

I have a feeling I’m supposed to try to remap my vscode/python extension that is installed in the C drive to where my anaconda is saved which is the H drive, but I’m not sure how to do that in the vs code settings. Any help would be greatly appreciated.

Follow Up to Original

user8408080 was correct that removing the space did help. I also modified the path to the anaconda environment to my companies drive nomenclature,

instead of H: it used something like \companyuser…

Now that I fixed that it’s kicking out another error saying the system cannot find the path specified even though the path is correct.

Executing code failed : Error: Activating Python 3.7.3 64-bit ('base': conda) to run 
Jupyter failed with Error: Command failed:\apachecorp.comfilesSanAntonioHomePaul.VictorDocumentsContinuumanaconda3Scriptsactivate base && 
echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && 
python c:/Users/paul.victor/.vscode/extensions/ms-python.python-2019.11.50794/pythonFiles/printEnvVariables.py The system cannot find the path specified. .
Asked By: PVic

||

Answers:

Looks like your Anaconda in PATH and Python Path in VSCode are pointing in different places.

First, check under system variables that your Anaconda is mapped to PATH based off where it is installed.

1- Click Start Menu Windows logo, type “path” click on “edit the system environment labels”

2- Under PATH for User Variables, if VSCode installed correctly to it, you will see the location of the bin file. Add to the PATH variable if it is not there. Mine looked like C:UsershSinAppDataLocalProgramsMicrosoft VS Codebin

3 – Under PATH for System Variables, if Anaconda installed correctly to it, you will see the associated paths. There are multiple files/directories that should be a part here. Verify existence before adding as some of these are specific to when Anaconda installed and what settings you chose.

C:ProgramDataAnaconda3; C:ProgramDataAnaconda3Librarymingw-w64; C:ProgramDataAnaconda3Libraryusrbin; C:ProgramDataAnaconda3Librarybin; C:ProgramDataAnaconda3Scripts

4 – Once all Path setups of Anaconda are confirmed, you should be able to call python from the terminal regardless of directory terminal is in. If not, your VSCode doesn’t have the correct interpreter mapped. Go to VSCode -> File -> Preferences -> Settings and then search as below to find the Python:Python Path setting. It should map to the root installation of your Anaconda. Standard is C:ProgramDataAnaconda3

VSCode Settings

5 – If still not working, your installations went to haywire and will require a reinstall of both applications. Install Anaconda first, make sure to check off the box to add to PATH, this is not default checked in the base installation. Then install VSCode, and set as default text editor. The Anaconda extension pack should come up as recommended, which will tie the two softwares together seamlessly if installed after Anaconda.

Answered By: hSin

I had the same issue. I was using Powershell on vscode instead of cmd.
What worked for me was to open a new cmd terminal on vscode. Then I switched to my conda env using:

conda activate my_env_name

After running this the option of my_env_name started showing in the select python interpreter drop down

Answered By: Siddharth Singi

BEFORE UNINSTALLING AND REINSTALLING AS A LAST RESORT:

In addition to hSin’s answer, in VSCode settings, set the "Python: Conda Path" to the root directory of your Anaconda Install folder (The same path you set "Python: Python Path" to). This did the trick for me, so it’s worth a shot before uninstalling and reinstalling.

Answered By: ItsCardiBBaby

According to hSin’s answer, I just set the following path to system environment variables of PATH:

  1. c:users[username]anaconda3
  2. c:users[username]anaconda3Scripts
  3. c:users[username]anaconda3Librarybin

Then restart VS Code, and it worked!

Answered By: Jabir

Install ipykernel in your conda env for it to get detected for .ipynb in visual studio code

pip install ipykernel
Answered By: Vivek Dani
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.