Could the reason why I can't select any kernels in VS Code be this error?

  • Thread starter Thread starter arhzz
  • Start date Start date
Click For Summary
SUMMARY

The issue of not being able to select kernels in Visual Studio Code (VS Code) while working with Jupyter notebooks is often due to improper environment setup or missing extensions. Users must ensure that the Python and Jupyter extensions are installed and that the correct Python environment is activated. Key steps include installing the ipykernel package and launching VS Code from the terminal using the 'code' command to maintain the environment context. A successful workaround involves explicitly opening the .ipynb file through the "Open File" option in VS Code.

PREREQUISITES
  • Familiarity with Miniconda and environment management
  • Understanding of Jupyter notebooks and kernels
  • Basic knowledge of Visual Studio Code extensions
  • Proficiency in using terminal commands for Python and Conda
NEXT STEPS
  • Learn how to configure Python environments in VS Code
  • Research the installation and configuration of Jupyter kernels
  • Explore troubleshooting techniques for VS Code extensions
  • Understand how to use terminal commands to manage Conda environments
USEFUL FOR

Developers working with Jupyter notebooks in VS Code, data scientists managing Python environments, and anyone troubleshooting kernel selection issues in VS Code.

arhzz
Messages
284
Reaction score
58
I am trying to run an .ipynb file and have installed Miniconda as well as created an environment as such

-conda create -n <env_name> python=3.7 ipykernel jupyter

I am assuming this is successful as I can activate this environment via the anaconda prompt and following command

-conda activate <env_name>

Then I downloaded and installed VS code and I am trying to edit an .ipynb file. I want to select a kernel, via VS Code but when I press the button on the upper right corner I am greeted with the message that I need to install Python and Jupyter extensions. As soon as I do that the following error shows up

"Extension activation failed run the 'Developer: Toggle Developer Tools' command for more information

Source: Jupyter (Extension)"

and I am not able to select any kernel.Additionaly,when I try running any Jupyter related commands such as

"Jupyter: Create Interactive Window"

I get error messages of the following type:

Command 'Jupyter: Create Interactive Window' resulted in an error (command 'jupyter.createnewinteractive' not found)

This error is common as far as I know and has been discussed here at StackOverflow. See following link Extension activation failed, run the 'Developer: Toggle Developer Tools' command for more information

Now I have tried the solution that was suggested on this question and it did not work. I tried installing prior versions of jupyter as well as tried completely deleting the extensions from the extensions folder. My last resort was reinstalling VS code altogether but that either did not resolve the issue.

So my question is could this be the cause of me not being able to select the kernel? If so how do I resolve this issue.

Many thanks!
 
Technology news on Phys.org
Try doing it without the environment switch. Most devs install VS Code separately so its available in any environment.
 
What do you mean without the environment switch? Could you elaborate more.
On a side note I am now certain it is a VS code issue since I tried doing it the oldschool way and just opened a juptyer notebook and it worked just fine.
 
I misread what you were doing.

The suggestions I saw were:

1) Make sure that after switching to your new environment, you can run the Python command

//// which python
//// python --version

On my macOS, there is no Python; instead you call it up via python3.

2) Add Jupyter kernel for notebooks:

//// python -m pip install ipykernel
//// python -m ipykernel install --user --name xyz --display-name "Python (xyz)"

3) After switching to your new environment, when starting up VS Code, do it via the 'code' command to be sure it's got the same environment.

//// code .

4) You may need to initialize conda in your .zshrc (or .bashrc...):

//// conda init zsh // (or whatever shell you're using: bash, sh, csh, ksh...
 
Last edited:
jedishrfu said:
I misread what you were doing.

The suggestions I saw were:

1) Make sure that after switching to your new environment, you can run the Python command

$$ which python
$$ python --version

On my macOS, there is no Python; instead you call it up via python3.

2) Add Jupyter kernel for notebooks:

$$ python -m pip install ipykernel
$$ python -m ipykernel install --user --name xyz --display-name "Python (xyz)"

3) After switching to your new environment, when starting up VS Code, do it via the 'code' command to be sure it's got the same environment.

$$ code .

4) You may need to initialize conda in your .zshrc (or .bashrc...):

$$ conda init zsh // (or whatever shell you're using: bash, sh, csh, ksh...
Ah I see, already did that. unfortunately did not help. Guess I am going to stick with the oldschool way
 
Some comments recommended manually pointing VS Code to the Python executable via its configuration settings.
 
  • Like
Likes   Reactions: arhzz
Okay so just to get back to everyone. I fixed it; it turns out when opening the file in VScode you need to go explicitly to the file with "Open File" and search for your .ipynb. Than after opening it that way the kernel shows up and it works fine.

Thanks everyone!
 
  • Like
Likes   Reactions: jedishrfu
You are knighted as a true Jedi hacker of the highest esteem in the realm of software engineering and beyond.

—-

These types of issues plague developers and end users all the time and it takes perseverance to find a solution or just a workaround.

Sadly, sometimes you can't find an online solution because so few bother to go back and explain what caused their issue and how they fixed it.

—-

On another note:

Sometimes, being honest about what happened can have downsides especially at work. Some superficial bosses interpret your honesty and perseverance as weakness and a waste of time which over time leads to perceived poor performance ratings.

Look for the boss who appreciates your hard work and perseverance in the face of an insurmountable problem and rewards you for your efforts.

—-

Thanks for sharing your solution.

May the Force be with you,

Jedi
 
  • Like
Likes   Reactions: arhzz

Similar threads

  • · Replies 17 ·
Replies
17
Views
3K
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
1
Views
5K
  • · Replies 14 ·
Replies
14
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
5
Views
15K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
1
Views
2K