Unfortunately I am not able to debug Jupyter Notebooks in Visual Studio Code. Maybe somebody has an idea why?
Detailed description:
After pressing "F5" the debugger (popup) starts as expected. Everything seems to run fine. "Only" that it doesn't stop at my breakpoints.
Debugging normal (i.e. non-jupyter-notebook) python scripts works without problems.
I have added the line '"jupyter.experimental.debugging": true,' to my 'settings.json'.
I use the latest VScode version 1.60.2.
There is only one python version installed on my laptop. Namely the latest anaconda distribution. I've also runned "conda update anaconda", "conda update python" and "pip install ipykernel". It shows that I use "ipykernel: 6.2.0".
Running Debugger
Now it works for me. With pressing "F5" I get the above described wrong behavior. But with pressing "Debug Cell" next to the play button (or Ctrl + Alt + Shift + Enter) it works fine:
Related
To note:
Pressing F5 (start debugging) correctly activates the conda environment
The environment of the IDE is indeed the desired conda environment. Python 3.9.7 ('conda environment name': conda)
The conda environment works if done through the terminal instead of the F5 debugging feature
After the environment is activated and I press F5 nothing happens and nothing is logged to the visual studio code logs. It does not work with any conda environment I have including 'base'.
This is the only thing that happens when I press F5:
Starts debugging, as expected.
One / two seconds later:
If I change the code interpreter to just Python 3.9.7 the code does in fact run. And again, if I run the conda enviroment THROUGH the terminal instead of F5 (and giving up on debugging, which I need) the conda enviroment also works.
To reiterate, no debug logs in Visual Studio Code, including files.
Any idea on how to tackle this? Been stuck for a while.
Machine is an ubuntu 20.04
Seems to be a bug with VS Code (issue link). Apparently, it was supposed to be fixed, but it still wasn't working for me. The issue was with new the new Python extension and older versions of Conda.
So first of all try updating Conda. For me it still wasn't working because VS Code didn't have the appropriate permissions, so I had to launch it with admin rights. Now it works.
I am trying to run a jupyter notebook on my Windows machine by using WSL2 to run it in Ubuntu 20.04. It was working perfectly fine yesterday but today it's not selecting a Python Interpreter. I have tried reinstalling Ubuntu, Anaconda and Visual Studio Code.
When I run
code path_to_notebook.ipynb
It opens the window below:
visual_studio_code
After a couple seconds the box (that I've made a yellow square around) pops up. When I click in the "Select Python Interpreter" button and select the interpreter that I want (~/anaconda3/bin/python) nothing happens.
The Select Python Interpreter (red box) also stays there.
What should I do?
I've gotten around the problem by using $ jupyter notebook --no-browser in the terminal.
Unfortunately, this means that additional computer resources are required to run the notebook in my browser over a text editor. But it gets the job done.
visual studio code, pressing run does not work on mac. Let say I want to print the word "Hello" and run the code print("Hello"), it will not be executed. I tried reinstalling python and visual studio but I could't resolve the problem.
When this happens to me, the Python interpreter borked and I need to press ctrl + c (abort) in the terminal a couple of times. It's still in the Python process and vscode is trying to input the run command into a Python process that's not actually a terminal.
I ran into the same issue. Figured out that I forgot to select the Add Python 3.8 to PATH while installing. You can either choose to uninstall and reinstall Python and make sure to select the above option OR you can manually update the user environment variable for PATH and add the path to scripts and python like the following.
C:\Users\<addyourusernamehere>\AppData\Local\Programs\Python\Python38-32\Scripts\
C:\Users\<addyourusernamehere>\AppData\Local\Programs\Python\Python38-32\
For me, downgrading VS Code extension called Python helped.
This shows where the option to install another version is in VS Code Extensions
As for today, I had to go back to version 2021.11.1422169775
M1 MacBook, macOS Monterey 12.2.1
I want to be able to have a working jupyter notebook working for VS code out of the box, with minimal work on my side.
I tried opening a jupyter notebook. I immediately found the interpreter and used my conda env with the command pellet (command + shift + P then in the drop down menu found my conda env). This seems to make the terminal work since which python points to the right place:
(automl-meta-learning) brandomiranda~/automl-meta-learning ❯ which python
/Users/brandomiranda/miniconda3/envs/automl-meta-learning/bin/python
also running python scripts from VS Code seems to be working fine too, see output:
(automl-meta-learning) brandomiranda~/automl-meta-learning ❯ /Users/brandomiranda/miniconda3/envs/automl-meta-learning/bin/python /Users/brandomiranda/automl-meta-learning/python_playground.py
x = 1
my_str = this is a string
y = 2
but when I try the jupyter notebook it doesn't work.
Most noticeably my VS code does not have a kernel connected, look at the screenshot:
I tried clicking on a couple of arrows as suggested on reddit (vs_code_jupyter_server_no_kernel_python_not):
When I try running things in my jupyter notebook I get the following error:
Error: Activating Python 3.7.6 64-bit ('base': conda) to run Jupyter failed with Error: StdErr from ShellExec, /Users/brandomiranda/.bashrc: line 31: jump-module.bash: No such file or directory
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run
$ conda init
Currently supported shells are:
- bash
- fish
- tcsh
- xonsh
- zsh
- powershell
See 'conda init --help' for more information and options.
IMPORTANT: You may need to close and restart your shell after running 'conda init'.
.
which is strange. My shell is not even bash so I don't know why that message is being shown to me (maybe VS Code doesn't know Mac OS Catalina uses zsh? not sure how to fix that for VS Code). Regardless, I proceeded to do what I think the error message is suggesting. So I did the following:
I ran conda init and then went down to the terminal inside vs code and restarted the shell by running zsh but the jupyter kernel still doesn't work on my notebook in vs code. Not sure what's wrong.
In addition, I did what the error message suggested:
(automl-meta-learning) brandomiranda~/automl-meta-learning ❯ conda init zsh
no change /Users/brandomiranda/miniconda3/condabin/conda
no change /Users/brandomiranda/miniconda3/bin/conda
no change /Users/brandomiranda/miniconda3/bin/conda-env
no change /Users/brandomiranda/miniconda3/bin/activate
no change /Users/brandomiranda/miniconda3/bin/deactivate
no change /Users/brandomiranda/miniconda3/etc/profile.d/conda.sh
no change /Users/brandomiranda/miniconda3/etc/fish/conf.d/conda.fish
no change /Users/brandomiranda/miniconda3/shell/condabin/Conda.psm1
no change /Users/brandomiranda/miniconda3/shell/condabin/conda-hook.ps1
no change /Users/brandomiranda/miniconda3/lib/python3.7/site-packages/xontrib/conda.xsh
no change /Users/brandomiranda/miniconda3/etc/profile.d/conda.csh
no change /Users/brandomiranda/.zshrc
No action taken.
but it seems it made no difference.
Any idea how to fix this?
I was suggessted by the developers of the VS code python extension to follow whatever they did here:
https://github.com/microsoft/vscode-python/issues/9566
but I can't figure out exactly it is they want me to do.
How do I fix this?
Related resources:
reddit: https://www.reddit.com/r/vscode/comments/eq2bfv/vs_code_jupyter_server_no_kernel_python_not/
gitissue: https://github.com/microsoft/vscode-python/issues/9636
I initially thought it was a conda issue so I looked into this question: Activate conda environment stopped working in vscode
https://www.reddit.com/r/vscode/comments/eshxka/how_does_one_connect_a_jupyter_kernel_to_vs_code/
https://www.quora.com/unanswered/How-does-one-connect-a-Jupyter-Kernel-to-VS-Code-if-one-does-not-connect-automatically
You need to select the python interpreter for jupyter, you can do it by following the step
Open command panel
Mac: CMD+Shift+P
PC: CTRL+SHIFT+P
Then search for select Interpreter to start jupyter server then hit enter, it will list all the interpreter, then select any interpreter and done!
it's just a one time process, after this, it will get connected automatically.
As bizarre as it seems, I also noticed this the other day and the only thing that works so far for me is to open VS Code by launching it from the Anaconda Navigator:
Then I get, as expected:
If you see the very long discussion I had in the git issue (https://github.com/microsoft/vscode-python/issues/9566) once I removed all the errors thrown by my .bashrc and .zhrc, the jupyter feature in VS code started working for me again. It's super weird (specially because I am NOT using bash at all and I am using zsh as my shell, I would have expected VS code to be robust to my .SHELLrc files throwing errors but it's not).
If that doesn't work, then you might have to install the vsix view extension and install the ms-python-insiders.vsixlinked in the issue (https://github.com/microsoft/vscode-python/issues/9566).
If on Windows VSCode, what worked for me was installing and enabling the Python and Jupyter extensions, then CTRL+SHIFT+P, select Interpreter to start jupyter server. Those extensions were the bottleneck.
I have been using vscode for only css and html and pycharm for python and lately I have switched to vscode also for my python scripts . I did all the necessary configurations and extensions installations I even installed code runner but so far I have not been able to properly run my python scripts without passing through the debug face when I click on the run button it still shows only the output from the previous run.
I believe you are trying to run the code like a Jupyter notebook. If you highlight code and press shift+enter it should turn on a python interpreter that runs the code in a new pane.