0

I'm fairly new to all of this and trying to self-teach. I only have really a vague understanding of concepts like virtual environments, shells, and kernels. I'm currently trying to generate a GUI with tkinter in Jupyter Notebooks. I was having trouble doing this in Pycharm until I changed to a different interpreter. I don't fully understand why this resolved the problem, but I believe it had something to do with using the proper version of python to interpret the script. Unfortunately, I need my python scripts to run in Jupyter, but I can't get the tkinter module to work when I run it in a notebook. I'm not sure how to change the interpreter or if that would even be what I need to do to fix the problem.

Here's the error:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-f463ac1a0eae> in <module>
      1 #Creating GUI with tkinter
----> 2 from tkinter.constants import *
      3 
      4 
      5 def send():

/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/tkinter/__init__.py in <module>
     35 import types
     36 
---> 37 import _tkinter # If this fails your Python may not be configured for Tk
     38 TclError = _tkinter.TclError
     39 from tkinter.constants import *

ModuleNotFoundError: No module named '_tkinter'

Any help would be greatly appreciated!

Kyle
  • 155
  • 2
  • 9

1 Answers1

0

See, your error specifies that if python fails to import _tkinter,your Python may not be configured for Tk. You need to edit your python installation.

If it fails with "No module named _tkinter", your Python configuration needs to be modified to include this module (which is an extension module implemented in C). Do not edit Modules/Setup (it is out of date). You may have to install Tcl and Tk (when using RPM, install the -devel RPMs as well) and/or edit the setup.py script to point to the right locations where Tcl/Tk is installed. If you install Tcl/Tk in the default locations, simply rerunning "make" should build the _tkinter extension.

  • More info: https://stackoverflow.com/questions/5459444/tkinter-python-may-not-be-configured-for-tk –  May 27 '21 at 16:49
  • How do I rerun make? – Kyle May 27 '21 at 17:11
  • Run this command and then check: ```sudo apt-get install tk8.6-dev``` –  May 27 '21 at 17:13
  • Check this: https://askubuntu.com/questions/543451/configure-tkinter-for-python3-4-2 –  May 27 '21 at 17:14
  • apt-get is for package management if you're using linux-based Ubuntu, right? I'm using a Mac OS and usually use Homebrew for package management, but I can't locate a formula/cask named python3-tk or tk8.6-dev – Kyle May 27 '21 at 17:22