Matplotlib-inline and Ipython Error when running SCT in Jupyter notebook/lab

I was trying to run SCT functions in Jupyter notebook, but some functions return the following errors:

Traceback (most recent call last):
  File "/Users/en_tetteh/NEUROPOLY/spinalcordtoolbox/spinalcordtoolbox/scripts/sct_process_segmentation.py", line 30, in <module>
    from spinalcordtoolbox.scripts import sct_maths
  File "/Users/en_tetteh/NEUROPOLY/spinalcordtoolbox/spinalcordtoolbox/scripts/sct_maths.py", line 18, in <module>
    import matplotlib.pyplot as plt
  File "/Users/en_tetteh/NEUROPOLY/spinalcordtoolbox/python/envs/venv_sct/lib/python3.7/site-packages/matplotlib/pyplot.py", line 2230, in <module>
    switch_backend(rcParams["backend"])
  File "/Users/en_tetteh/NEUROPOLY/spinalcordtoolbox/python/envs/venv_sct/lib/python3.7/site-packages/matplotlib/pyplot.py", line 267, in switch_backend
    class backend_mod(matplotlib.backend_bases._Backend):
  File "/Users/en_tetteh/NEUROPOLY/spinalcordtoolbox/python/envs/venv_sct/lib/python3.7/site-packages/matplotlib/pyplot.py", line 268, in backend_mod
    locals().update(vars(importlib.import_module(backend_name)))
  File "/Users/en_tetteh/NEUROPOLY/spinalcordtoolbox/python/envs/venv_sct/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'matplotlib_inline'
Traceback (most recent call last):
  File "/Users/en_tetteh/NEUROPOLY/spinalcordtoolbox/spinalcordtoolbox/scripts/sct_process_segmentation.py", line 30, in <module>
    from spinalcordtoolbox.scripts import sct_maths
  File "/Users/en_tetteh/NEUROPOLY/spinalcordtoolbox/spinalcordtoolbox/scripts/sct_maths.py", line 18, in <module>
    import matplotlib.pyplot as plt
  File "/Users/en_tetteh/NEUROPOLY/spinalcordtoolbox/python/envs/venv_sct/lib/python3.7/site-packages/matplotlib/pyplot.py", line 2230, in <module>
    switch_backend(rcParams["backend"])
  File "/Users/en_tetteh/NEUROPOLY/spinalcordtoolbox/python/envs/venv_sct/lib/python3.7/site-packages/matplotlib/pyplot.py", line 267, in switch_backend
    class backend_mod(matplotlib.backend_bases._Backend):
  File "/Users/en_tetteh/NEUROPOLY/spinalcordtoolbox/python/envs/venv_sct/lib/python3.7/site-packages/matplotlib/pyplot.py", line 268, in backend_mod
    locals().update(vars(importlib.import_module(backend_name)))
  File "/Users/en_tetteh/NEUROPOLY/spinalcordtoolbox/python/envs/venv_sct/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/Users/en_tetteh/NEUROPOLY/spinalcordtoolbox/python/envs/venv_sct/lib/python3.7/site-packages/matplotlib_inline/backend_inline.py", line 15, in <module>
    from IPython.core.interactiveshell import InteractiveShell
ModuleNotFoundError: No module named 'IPython'

@Enoch_Tetteh Thank you for reporting this issue. While our team is looking into it, maybe this Jupyter notebook that uses SCT could be useful?

Thank you, and I had a discussion about it with @joshuacwnewton. The fix is to install matplotlib-inline and Ipython in your SCT environment.

Example:
!${SCT_DIR}/python/envs/venv_sct/bin/pip install matplotlib-inline

!${SCT_DIR}/python/envs/venv_sct/bin/pip install Ipython