spinal-cord-7t / coil-qc-code

7T Spinal Cord Coil QC Analysis Code
https://spinal-cord-7t.github.io/coil-qc-code/README.html
1 stars 1 forks source link

ModuleNotFoundError: No module named 'IPython': when running notebook in debug mode via VScode #145

Open jcohenadad opened 3 weeks ago

jcohenadad commented 3 weeks ago

getting this when running notebook in debug mode via VScode:

sct_qc -i sub-MGH2_UNIT1.nii.gz -s sub-MGH2_UNIT1_seg_labeled.nii.gz -p sct_label_vertebrae -qc /Users/julien/code/coil-qc-code/data-human/qc -qc-subject sub-MGH2
--

*** Generating Quality Control (QC) html report ***
Traceback (most recent call last):
  File "/Users/julien/code/spinalcordtoolbox/spinalcordtoolbox/scripts/sct_qc.py", line 125, in <module>
    main(sys.argv[1:])
  File "/Users/julien/code/spinalcordtoolbox/spinalcordtoolbox/scripts/sct_qc.py", line 108, in main
    generate_qc(fname_in1=arguments.i,
  File "/Users/julien/code/spinalcordtoolbox/spinalcordtoolbox/reports/qc.py", line 632, in generate_qc
    qc_image._make_QC_image_for_3d_volumes(img, mask, plane, imgs_to_generate)
  File "/Users/julien/code/spinalcordtoolbox/spinalcordtoolbox/reports/qc.py", line 228, in _make_QC_image_for_3d_volumes
    fig = mpl_plt.figure()
  File "/Users/julien/code/spinalcordtoolbox/python/envs/venv_sct/lib/python3.9/site-packages/matplotlib/pyplot.py", line 1027, in figure
    manager = new_figure_manager(
  File "/Users/julien/code/spinalcordtoolbox/python/envs/venv_sct/lib/python3.9/site-packages/matplotlib/pyplot.py", line 549, in new_figure_manager
    _warn_if_gui_out_of_main_thread()
  File "/Users/julien/code/spinalcordtoolbox/python/envs/venv_sct/lib/python3.9/site-packages/matplotlib/pyplot.py", line 526, in _warn_if_gui_out_of_main_thread
    canvas_class = cast(type[FigureCanvasBase], _get_backend_mod().FigureCanvas)
  File "/Users/julien/code/spinalcordtoolbox/python/envs/venv_sct/lib/python3.9/site-packages/matplotlib/pyplot.py", line 358, in _get_backend_mod
    switch_backend(rcParams._get("backend"))
  File "/Users/julien/code/spinalcordtoolbox/python/envs/venv_sct/lib/python3.9/site-packages/matplotlib/pyplot.py", line 415, in switch_backend
    module = backend_registry.load_backend_module(newbackend)
  File "/Users/julien/code/spinalcordtoolbox/python/envs/venv_sct/lib/python3.9/site-packages/matplotlib/backends/registry.py", line 323, in load_backend_module
    return importlib.import_module(module_name)
  File "/Users/julien/code/spinalcordtoolbox/python/envs/venv_sct/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/Users/julien/code/spinalcordtoolbox/python/envs/venv_sct/lib/python3.9/site-packages/matplotlib_inline/__init__.py", line 1, in <module>
    from . import backend_inline, config  # noqa
  File "/Users/julien/code/spinalcordtoolbox/python/envs/venv_sct/lib/python3.9/site-packages/matplotlib_inline/backend_inline.py", line 13, in <module>
    from IPython.core.interactiveshell import InteractiveShell
ModuleNotFoundError: No module named 'IPython'

Probably related to #134

jcohenadad commented 3 weeks ago

One thing, is that IPython is not in the requirements.txt, but it is install in my local env. But in any case, we should add it to the requirements.txt so GHA can properly run the notebook

jcohenadad commented 3 weeks ago

Installing IPython and updating my local venv solved it. Will push the fix shortly.

jcohenadad commented 3 weeks ago

pushed: af8ad9a

jcohenadad commented 3 weeks ago

FWIT: The issue reappeared, even though I've been using the same VScode and environment. I think there might be a feature in jupyter and/or VScode that times how long a notebook runs, and after a while IPython becomes somehow unloaded (???).

jcohenadad commented 2 weeks ago

Reopening this issue, and also opened an issue on SCT.

In the meantime, i will comment out all the calls to sct_qc in the notebook, to avoid excessive errors. Will need to un-comment once the issue is fixed.