Code Monkey home page Code Monkey logo

Comments (5)

lassoan avatar lassoan commented on September 25, 2024

The Slicer Jupyter kernel worked for me in VS code a few months ago, but not anymore. When I executed a cell in the notebook I got an error message that the connection_file was not found in the argument list in kernel.json, which was clearly wrong. After adding a dummy connection_file argument, it complained that it expects the kernel arguments to be exactly a certain format (something like python-executable -m modulename arg1 arg2...), which is nonsense (the server should not dictate a specific format for how to call the kernel executable). I've also tried "Existing" Jupyter server options in VS Code GUI and when I copied the server address there and hit Enter, nothing happened. There may be things around the Slicer kernel that work slightly differently than a regular Python kernel, but it looks like notebook support in VS code is broken or at least really fragile.

I've added this line to the slicer startup file (C:\Users\andra\.slicerrc.py) to print what VS code does:

print("arguments="+repr(slicer.app.arguments()))

And I got this in the application log:

[INFO][Stream] 08.02.2021 18:50:22 [] (unknown:0) - arguments=(
  'C:\\Users\\andra\\AppData\\Local\\NA-MIC\\Slicer 4.13.0-2021-02-04\\bin\\SlicerApp-real.exe',
  'c:\\Users\\andra\\.vscode\\extensions\\ms-python.python-2021.1.502429796\\pythonFiles\\pyvsc-run-isolated.py',
  'c:\\Users\\andra\\.vscode\\extensions\\ms-python.python-2021.1.502429796\\pythonFiles\\interpreterInfo.py')

So, it seems that VS code wants to retrieve information about the interpreter with some custom script, which is totally arbitrary. VS code imposes restrictions and makes assumptions that may be OK for a plain Python kernel using Python or conda distribution but totally inappropriate for custom kernel implementations.

You can try to go back to an earlier Python/Jupyter extension version in VS code or wait for a newer version that has better interoperability.

from slicerjupyter.

gregspangenberg avatar gregspangenberg commented on September 25, 2024

Thanks for looking into this I appreciate it! I will rollback to an earlier Jupyter extension or simply use the web based jupyter if that doesn't work.

from slicerjupyter.

lassoan avatar lassoan commented on September 25, 2024

OK! Let us know if rollback works.

from slicerjupyter.

lassoan avatar lassoan commented on September 25, 2024

VS Code still cannot start the server in Slicer's virtual Python environment but if the server is started from Slicer then VS Code can connect to the running server:

  • Start Slicer, go to JupyterKernel module, click Start Jupyter server
  • Get the Jupyter server URL from the Slicer application log (it should be something like http://localhost:8888/lab?token=afc2a22bbe61149ae7c2e831645e5b28384203eb3c3c2da5), copy to the clipboard
  • In Visual Studio code, open a notebook, click in the lower-right corner on "Jupyter server: ..." then select at the list at the top center "Pick how to connect to jupyter" -> "Existing", paste the server URL from the clipboard and hit Enter
  • If in the top-right corner the kernel is not "Slicer 4.13" then click there and choose "Slicer 4.13" from the list that appears in the top center

from slicerjupyter.

lassoan avatar lassoan commented on September 25, 2024

I've made some fixes to improve compatibility when using SlicerJupyter as a local server. How to make local server work:

  • select PythonSlicer as Python interpreter
  • choose Slicer-4.13 as kernel

It seems that the kernel does not show up if the language in kernel.json is set to "python" and changing it to anything else (for example "pythonX") makes it appear.

It may also be necessary to install the kernelspec in the PythonSlicer requirement, replacing --user by --sys-prefix.

Overall, VSCode Jupyter extension seems to struggle with all but the most basic Jupyter configurations. There are dozens of open issues and support for custom kernels, such as XEUS (that Slicer uses) is quite low on the priority list.

from slicerjupyter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.