Hello, I am using Slicer 4.11.0-2019-08-29 with jupyter notebook. I would like to be able to use matplotlib in the notebook to do things like plot histograms. I have successfully pip-installed matplotlib with
slicer.util.pip_install('matplotlib'), and get no errors with
import matplotlib. However, if I
import matplotlib.pyplot as plt, I get the following error message:
Traceback (most recent call last): File "<console>", line 1, in <module> File "C:\Users\mikeb\AppData\Local\NA-MIC\Slicer 4.11.0-2019-08-29\lib\Python\Lib\site-packages\matplotlib\pyplot.py", line 2355, in <module> switch_backend(rcParams["backend"]) File "C:\Users\mikeb\AppData\Local\NA-MIC\Slicer 4.11.0-2019-08-29\lib\Python\Lib\site-packages\matplotlib\pyplot.py", line 221, in switch_backend backend_mod = importlib.import_module(backend_name) File "C:\Users\mikeb\AppData\Local\NA-MIC\Slicer 4.11.0-2019-08-29\lib\Python\Lib\importlib\__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "C:\Users\mikeb\AppData\Local\NA-MIC\Slicer 4.11.0-2019-08-29\lib\Python\Lib\site-packages\matplotlib\backends\backend_tkagg.py", line 1, in <module> from . import _backend_tk File "C:\Users\mikeb\AppData\Local\NA-MIC\Slicer 4.11.0-2019-08-29\lib\Python\Lib\site-packages\matplotlib\backends\_backend_tk.py", line 6, in <module> import tkinter as tk File "C:\Users\mikeb\AppData\Local\NA-MIC\Slicer 4.11.0-2019-08-29\lib\Python\Lib\tkinter\__init__.py", line 36, in <module> import _tkinter # If this fails your Python may not be configured for Tk ModuleNotFoundError: No module named '_tkinter'
I am guessing that, as the error message suggests, the Slicer python may not be configured for Tk (since it uses Qt for GUI), but I’m not sure how to fix this. I have not had any luck googling to figure out how to install Tk because everywhere I look says “Tk is already included with standard python, you don’t have to install it”.
Any suggestions? I just want to use matplotlib for basic plotting and data exploration as I am working on algorithm development for a segmentation/processing module. If there is another easy-to-use alternative which will already work with Slicer that would be fine. I have a little experience with matplotlib and know it works well with jupyter notebooks, so that’s why I was trying to use that tool.
Thanks for considering and for any suggestions!