Could not connect python3 kernel to Polyglot notebook
renbud opened this issue · comments
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. ):
- OS
- [X ] Windows 11
- Windows 10
- macOS
- Linux (Please specify distro)
- iOS
- Android
- Browser
- [ X] Chrome
- Edge
- Firefox
- Safari
- Frontend
- [ X] Jupyter Notebook
- Jupyter Lab
- nteract
- [X ] Visual Studio Code
- Visual Studio Code Insiders
- Visual Studio
- Other (please specify)
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.
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 #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.
@renbud you may want to check out #3397
Specifically, see if the following helps: #3397 (comment)