Monday, September 14, 2020

Fixing: "matplotlib error - no module named tkinter" in Windows 10

If you are using python 3.x in Windows 10 and encoutered this error: "matplotlib error - no module named tkinter", it's very possible that you didn't install the Tcl/Tk module when installing Python to your machine. The tkinter module comes from Tcl/Tk. Fear not, you don't need to uninstall and reinstall Python to fix it. You only need to modify your Python installation to install the missing Tcl/Tk support as follows:

  1. Go to Add/Remove Programs from Windows 10 search box. From there, select your Python installation, like this: 

  2. Then click the option to modify the Python installation. You'll be presented with this dialog: 

  3. Then click on the Modify option in the Python installer dialog. In the Optional Features dialog that shows up, make sure you checked the tcl/tk and IDLE option, like this (inside the red box): 

  4. Next, just follow the instruction after clicking on the Next button to apply the changes.  
After this, the matplotlib error should be fixed as the tkinter python module is installed. 

Note that even if you install the tcl/tk library via pip install successfully when encountering the matplotlib error, you will probably still left with the same matplotlib error. I'm not sure why it happened in my system. It's probably the module search path is somehow not working properly unless you do a "user/account-wide" or system-wide installation for the module to make it work. In any case, the solution above fixed the error in all cases that I have tested. I think it should work for you too. 

Post a Comment

No comments: