Configure Python interpreter for notebook in vscode to be the same as the interpreter for a conda environment

Question:

From my understanding of this source and what a python interpreter is, if I have an environment like this:

$ conda activate myenv
(myenv) $ python3
> import pandas as pd
> 

With no errors. And which python3 returns
/AbsPath/.conda/envs/myenv/bin/python3

Then in my Notebook in vscode I should be able to select this interpreter in the command pallet and not have an error importing pandas.

So open my-notebook.ipynb. Open command pallet and select Python: Select Interpreter, click + Enter interpreter path and then paste /AbsPath/.conda/envs/myenv/bin/python3 then I should be able to execute a cell that contains

(The vscode website says I should be able to set the interpreter for Jupyter Notebook environments this way.)

import pandas as pd

And not have an error thrown. But I get the error that I have no module named Pandas.

Am I doing something incorrectly or is this unexpected weird behavior?

I don’t think it’s actually using the correct interpreter because

import sys
print(sys.executable)

Prints /bin/python3 from my notebook while this same command from the command line gives me /AbsPath/.conda/envs/myenv/bin/python3.

I tried

import sys
sys.executable = '/AbsPath/.conda/envs/myenv/bin/python3'

To override it but that didn’t work (unsurprisingly).

Answers:

You need to check whether you have chosen the correct kernel.

Click the button in the upper right corner of the .ipynb file.

You can read document and this page for more details if you are new to jupyter notebook.

enter image description here

Answered By: MingJie-MSFT