dotnet / interactive

.NET Interactive combines the power of .NET with many other languages to create notebooks, REPLs, and embedded coding experiences. Share code, explore data, write, and learn across your apps in ways you couldn't before.
MIT License
2.8k stars 371 forks source link

Could not connect python3 kernel to Polyglot notebook #3556

Open renbud opened 1 month ago

renbud commented 1 month ago

Describe the bug

Please provide as much information as you can.

Please complete the following:

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

image

I installed python 3.12 using miniconda and created an environment called demo1 with jupyterlab and pandas. This environment works with a regular jupyter notebook in VSCode and also with jupyter lab. I also want to use powershell and SQL Server in a notebook, so I installed the Polyglot Notebook extension. This works fine for C# and SQL etc. But I also want to use python in the same notebook,. However: I could not get the following command to work:

!connect jupyter --kernel-name demo1 --conda-env demo1 --kernel-spec python3

I tried putting the path to python in my PATH variable and tried with and without the conda-env, different kernel names. Nothing works. I even tried using the URL and token parameters and pointing to the jupyter-labs server URL but got a permissions error.

xela-trawets commented 2 weeks ago

I had the same issue with python. Julia and R were straightforward to get connected up. But Python was a battle to get going. So many missing environment paths, so many binaries, connected by magic strings. In the end the following was useful

pip install ipykernel python -m ipykernel install --user --name=mykernelspec (thanks to https://github.com/dotnet/interactive/issues/3478)

ending up with the following "magic command" in dotnet interactive:

!connect jupyter --kernel-name mykernelspec --kernel-spec mykernelspec

here is my limited understanding... The ipykernel is the "engine", and that needs to be "pip installed" Dotnet interactive starts the ipykernel by looking in the kernel.json file I put the explicit path to python in the kernel definition; here is the mykernelspec\kernel.json:

{ "argv": [ "C:\path\python.exe", "-m", "ipykernel_launcher", "-f", "{connection_file}" ], "display_name": "mykernelspec", "language": "python", "metadata": { "debugger": true } }

Unclear how the kernel.json paths are communicated to dotnet interactive, but it works. The driving points for me as a dotnet developer are to be able work with my python coworkers, and use matplotlib etc. Looking forward to working flexibly with C# and Python.

webteckie commented 1 week ago

@renbud you may want to check out https://github.com/dotnet/interactive/issues/3397 Specifically, see if the following helps: https://github.com/dotnet/interactive/issues/3397#issuecomment-2023152891