Slicer/Jupyter integration: installing python packages

Hello,

I’m having trouble integrating 3D Slicer with Jupyter on my computer. I installed both Slicer and Jupyter, but am stuck on installing python packages. When I paste the below into the python interactor in Slicer as instructed here (https://github.com/Slicer/SlicerJupyter/blob/master/README.md), I get the error that pip_install is invalid syntax.

Thanks so much for your help

import os
if os.name=='nt':
    # There are no official pyzmq wheels for Python-3.6 for Windows, so we have to install manually
    pip_install("https://files.pythonhosted.org/packages/94/e1/13059383d21444caa16306b48c8bf7a62331ca361d553d2119696ea67119/pyzmq-19.0.0-cp36-cp36m-win_amd64.whl")
else:
    # PIL may be corrupted on linux, reinstall from pillow
    pip_install('--upgrade pillow --force-reinstall')
pip_install("ipywidgets pandas ipyevents ipycanvas")

What operating system do you use?
What error message do you get?

I’m on a Mac OS, and the specific error message is

File “”, line 7
pip_install(“ipywidgets pandas ipyevents ipycanvas”)
^
SyntaxError: invalid syntax

Probably the console is confused by the indentations. Either copy-paste the last line separately, or just copy-paste the two lines relevant for macOS:

pip_install('--upgrade pillow --force-reinstall')
pip_install('ipywidgets pandas ipyevents ipycanvas')

Hi Andras,

That gives me the error that
Traceback (most recent call last):
File “”, line 1, in
NameError: name ‘pip_install’ is not defined

Is there something I should do in addition to “import os” before executing these lines? I’m just following the instructions from the readme.

Thanks so much for your help.

You need to copy-paste these lines in 3D Slicer’s Python console.

Is that separate from the python interactor? I’m typing it into the Python interactor at the bottom of the screen

Yes, the Python interactor at the bottom of the Slicer application window shows a console of Slicer’s Python environment. Are there any error messages in the console before you type the command? Can you post a screenshot of how everything looks after you typed the command?

Could you try with slicer.util.pip_install instead of just pip_install?

Hi Andras,

There is no error message before I type the command. Do I need to import pip into this environment before I get started? I tried it with slicer.util.pip_install, and this is what I get

Which Slicer version do you use?

This is 3D slicer 4.10.2

OK, that explains everything. You need to use a recent Slicer Preview Release.

Hi Andras,

that worked – thanks! – but now when I try to pip_install(‘ipywidgets pandas ipyevents ipycanvas’) I get the error that “could not build wheels for argon-cffi which use PEP517 and cannot be installed directly”. Do you know what might be going on?

Thanks

Can you copy here the actual error message?

Could you run pip_install for each package separately to see which one triggers the error?

Pandas has no problem, but ipycanvas, ipywidgets, and ipyevents all give the same error message below, and when I try the command suggested in the warning in terminal, it aborts it

Thank you for all these information.

I searched for this error on the web and it seems that Jupyter recently switched to argon2-cffi crypto library to increase its security. Unfortunately, this library does not have binary package (wheel) for Python-3.6.7 on MacOS, that’s why you get the error.

You have a few options:

Option A: Let anaconda get/build the wheel for you. Install anaconda and type the following commands:

conda create -n slicerhelper python=3.6.7
conda activate slicerhelper
pip install argon2-cffi

After this, pip_install command in Slicer should succeed.

Option B. Find a download site for Python-3.6.7 macOS wheel for argon2-cffi and specify that using pip_install.

Option C. Use a Jupyter version that did not depend on argon2-cffi, by specifying an earlier version of ipywidgets or jupyter in pip_install

@jcfr Do you have any comment on this? Could we upgrade Slicer to Python-3.7? Or, could we build an argon2-cffi Python-3.6.7 macOS wheel and make it available for download?

1 Like

Let me give this a try, thank you!

While we could work with the upstream argon2-cffi project to have wheels, I suggest instead to spend time updating the python version used in Slicer from 3.6 to 3.7 (or 3.8).

This has been discussed here:

In the meantime, the community is helping to update from 3.6.7 to 3.6.12:

@lassoan

Option A worked, and I was able to get through the installation instructions on the readme, but now that Jupyter kernel and Slicer are connected, I tested this in Jupyter

import JupyterNotebooksLib as slicernb
slicernb.ViewDisplay()

and got this error message in my terminal, but nothing happens in my Jupyter notebook (no error message) or in Slicer

ERROR: during execute_request

make_tuple(): unable to convert arguments to Python object (compile in debug mode for details)

I was able to reproduce the issue. Most probably it is because of a recent upgrade of XEUS-Python kernel. I’ll investigate it a bit more and revert to the last known working version if I cannot figure out how to fix it.