Python Code Cell in Jupyter Notebook Cannot Use Conda Virtual Environment
See original GitHub issueSeemingly similar issue to https://github.com/microsoft/vscode-jupyter/issues/2616, filing a new issue on @DonJayamanne’s request.
Environment
- VS Code: v1.51.1
- Jupyter Extension: v2020.11.392013122
- Python Extension: v2020.11.371526539
- OS: Windows 10 Pro v1909
- Anaconda: v2020.07 (
anaconda), v1.7.2 (anaconda-client)
Description
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.
Steps to Reproduce
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=myenvOutput: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
myenvas 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.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)

Top Related StackOverflow Question
@IanMatthewHuff this is a known bug in core extension. Looks like some recent bug in core extension. Will find issue
Dupe of #4011