Seemingly similar issue to https://github.com/microsoft/vscode-jupyter/issues/2616, filing a new issue on @DonJayamanne's request.
anaconda), v1.7.2 (anaconda-client)I am using a Jupyter notebook with Python code cells in VS Code. After creating a new virtual environment using the standard Anaconda steps, I select the appropriate Python interpreter via the VS Code GUI.
I have registered the virtual environment with Jupyter using python -m ipykernel install --user --name=myenv and my virtual environment has the jupyter library installed. Note that the Jupyter, Anaconda, and Python extensions are all installed in VS Code as well.
I am able to use conda activate myenv and run code directly in the terminal perfectly fine. Unfortunately, when attempting to run the same code in the code cell inside the Jupyter notebook, I am unable to activate myenv; instead, I see that base is activated when I run !conda info --envs and !where python.
Would appreciate any suggestions.
In VS Code terminal (using Command Prompt):
conda create -n myenv python=3.8 pandas numpy matplotlib jupyter notebook
conda activate myenv
python -m ipykernel install --user --name=myenv
Output: Installed kernelspec myenv in C:\Users\ayush\AppData\Roaming\jupyter\kernels\myenv
conda info --envs
Output:
# conda environments:
#
base C:\Users\ayush\anaconda3
myenv * C:\Users\ayush\anaconda3\envs\myenvp
In new Jupyter notebook test.ipynb:
Select myenv as the Python interpreter via the VS Code GUI.

In Python code cell: !conda info --envs
Output:
# conda environments:
#
base * C:\Users\ayush\anaconda3
myenv C:\Users\ayush\anaconda3\envs\myenv
If I install additional libraries in myenv (e.g. PyTorch), they are unable to be loaded within the Jupyter notebook. For example, see below:

Thank you all for your help.
@ayushnoori we do have issues with Conda activation at times. Can you try something out for me? Could you please open up a command window with the myenv environment activated in Conda. Then from that command window open up vscode and run your scenario with myenv selected. See if that correctly uses your environment? Also make sure to check the kernel selector at the top right of the notebook. Make the myenv is selected there as well, as that selector is what the notebook is actively using.
Hi @IanMatthewHuff, thanks for the advice. I tried the first step before posting, to no avail. After activating myenv in the Anaconda GUI, I started the CMD.exe prompt from Anaconda, ran cd to my working directory, and launched VS Code via code .. Unfortunately, didn't change anything.
I see the kernel selector at the top right, here is what it looks like when I open the notebook (from Command Prompt):

When I click on "Busy", a dialog opens up in the command palette which allows me to select the virtual environment. If I specify myenv explicitly, the selector changes to:

If I attempt to then run a code cell, I get the following error pop up message:
StdErr from ShellExec, Did not find path entry C:\Users\ayush\anaconda3\bin for C:/Users/ayush/anaconda3/Scripts/activate && conda activate myenv && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python c:\Users\ayush\.vscode\extensions\ms-python.python-2020.11.371526539\pythonFiles\pyvsc-run-isolated.py c:/Users/ayush/.vscode/extensions/ms-python.python-2020.11.371526539/pythonFiles/printEnvVariables.py
If I attempt to then run a code cell, I get the following error pop up message:
StdErr from ShellExec,
@IanMatthewHuff this is a known bug in core extension. Looks like some recent bug in core extension. Will find issue
@DonJayamanne ran a brief test this morning and the issue seems to have been resolved. Has a fix been implemented?
@ayushnoori are you using VS Code insiders or VS Code Stable?
I can seem that someone reported this issue (on VSCode-python repo) got resolved after updating to the latest version of VS Code insiders.
Has a fix been implemented?
We didn't add any fix related to this.
Dupe of #4011
Most helpful comment
@IanMatthewHuff this is a known bug in core extension. Looks like some recent bug in core extension. Will find issue