[Python] How does one connect a Jupyter Kernel to VS Code if one does not connect...

Discussão em 'Python' iniciado por Stack, Abril 18, 2025.

  1. Stack

    Stack Membro Participativo

    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:

    [​IMG]

    I tried clicking on a couple of arrows as suggested on reddit (vs_code_jupyter_server_no_kernel_python_not):

    [​IMG]

    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:


    Continue reading...

Compartilhe esta Página