interactive icon indicating copy to clipboard operation
interactive copied to clipboard

Cannot connect to python kernel using provided command

Open odkken opened this issue 1 year ago • 4 comments

Describe the bug

Running the command from the documentation:

#!connect jupyter --kernel-name pythonkernel --kernel-spec python3

yields the following error: Error: System.ArgumentException: KernelSpec python3 not found at Microsoft.DotNet.Interactive.Jupyter.ZMQ.JupyterConnection.CreateKernelConnectionAsync(String kernelSpecName) in D:\a_work\1\s\src\Microsoft.DotNet.Interactive.Jupyter\ZMQ\JupyterConnection.cs:line 46 at Microsoft.DotNet.Interactive.Jupyter.JupyterKernelConnector.CreateKernelAsync(String kernelName) in D:\a_work\1\s\src\Microsoft.DotNet.Interactive.Jupyter\JupyterKernelConnector.cs:line 27 at Microsoft.DotNet.Interactive.Jupyter.ConnectJupyterKernelCommand.ConnectKernelsAsync(KernelInvocationContext context, InvocationContext commandLineContext) in D:\a_work\1\s\src\Microsoft.DotNet.Interactive.Jupyter\ConnectJupyterKernelCommand.cs:line 72 at Microsoft.DotNet.Interactive.CompositeKernel.<>c__DisplayClass21_0.<<AddKernelConnector>b__0>d.MoveNext() in D:\a_work\1\s\src\Microsoft.DotNet.Interactive\CompositeKernel.cs:line 271 --- End of stack trace from previous location --- at System.CommandLine.NamingConventionBinder.CommandHandler.GetExitCodeAsync(Object returnValue, InvocationContext context) at System.CommandLine.NamingConventionBinder.ModelBindingCommandHandler.InvokeAsync(InvocationContext context) at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass15_0.<<AddMiddleware>b__0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass12_0.<<UseHelp>b__0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass19_0.<<UseTypoCorrections>b__0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Invocation.InvocationPipeline.<InvokeAsync>g__FullInvocationChainAsync|2_0(InvocationContext context) at System.CommandLine.Parsing.ParseResultExtensions.InvokeAsync(ParseResult parseResult, IConsole console) at Microsoft.DotNet.Interactive.Commands.DirectiveCommand.InvokeAsync(KernelInvocationContext context) in D:\a_work\1\s\src\Microsoft.DotNet.Interactive\Commands\DirectiveCommand.cs:line 33 at Microsoft.DotNet.Interactive.Kernel.HandleAsync(KernelCommand command, KernelInvocationContext context) in D:\a_work\1\s\src\Microsoft.DotNet.Interactive\Kernel.cs:line 326 at Microsoft.DotNet.Interactive.KernelCommandPipeline.<BuildPipeline>b__6_0(KernelCommand command, KernelInvocationContext context, KernelPipelineContinuation _) in D:\a_work\1\s\src\Microsoft.DotNet.Interactive\KernelCommandPipeline.cs:line 60 at Microsoft.DotNet.Interactive.KernelCommandPipeline.SendAsync(KernelCommand command, KernelInvocationContext context) in D:\a_work\1\s\src\Microsoft.DotNet.Interactive\KernelCommandPipeline.cs:line 41

I am launching via an anaconda terminal after having activated an environment using code-insiders .

Do I need to modify pythonkernel or python3 in the above command to match the name of my python environment?

Which version of .NET Interactive are you using? (In a notebook, run the #!about magic command. ): Version: 1.0.446101+82cadfa197106a3f4a0fb95783e8ce6bb93c07b6

  • OS
    • [x] Windows 11
    • [ ] Windows 10
    • [ ] macOS
    • [ ] Linux (Please specify distro)
    • [ ] iOS
    • [ ] Android
  • Browser
    • [ ] Chrome
    • [ ] Edge
    • [ ] Firefox
    • [ ] Safari
  • Frontend
    • [ ] Jupyter Notebook
    • [ ] Jupyter Lab
    • [ ] nteract
    • [ ] Visual Studio Code
    • [x] Visual Studio Code Insiders
    • [ ] Visual Studio
    • [ ] Other (please specify)

Screenshots

If applicable, add screenshots to help explain your problem.

odkken avatar Sep 11 '23 19:09 odkken

same issue. i am on Windows 11. python 3.11 installed using chocolatey. and using python.

syedqutub avatar Sep 21 '23 19:09 syedqutub

After exploring the code base by the given stack trace it turns out that i did not have "jupyter" cli installed on my pc. so i did the "pip install jupyterlab" and then it worked for me!

syedqutub avatar Sep 23 '23 11:09 syedqutub

Can confirm. I get the same bug trying to run Python kernel by this command. I already had JupyterLab installed. Attempting to reinstall did not solve the issue.

pehkawn avatar Nov 14 '23 13:11 pehkawn

Ok, so checking Jupyter's kernelspec list, I found a workaround: I noticed that I could run R kernels, so I suspected it might have something to do with the path to the python3 kernel.

>jupyter kernelspec list
0.01s - Debugger warning: It seems that frozen modules are being used, which may
0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
0.00s - to python to disable frozen modules.
0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.
Available kernels:
  ir           C:\Users\palbja\AppData\Roaming\jupyter\kernels\ir
  julia-1.9    C:\Users\palbja\AppData\Roaming\jupyter\kernels\julia-1.9
  python3      C:\Users\palbja\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\share\jupyter\kernels\python3

As you can see, the R kernel (ir) is located in a different folder. I simply copied the python3 folder to C:\Users\palbja\AppData\Roaming\jupyter\kernels\. After restarting the .NET kernel in the Polyglot notebook, running the command #!connect jupyter --kernel-name pythonkernel --kernel-spec python3 will now start the Python kernel.

[Edit:] I should point out that I could run Python just fine before copying the folder to a different location. It is also worth noting that I installed Python 3.11 from Microsoft Store without admin privileges, which may have influenced the Python kernelspec path. Hope this is helpful finding a solution.

pehkawn avatar Nov 14 '23 14:11 pehkawn