Bohumír Zámečník

How to Install Tkinter With Python 3 on Mac

Tkinter is an old GUI toolkit, that has been popular also in some Python projects. Sometimes it might be tricky to install. If you just can’t get past ImportError: No module named '_tkinter', read on. We’ll install it with Python 3.4 on Mac OX S Yosemite and macports.

We’re assuming to have a Python 3 installation, possibly inside a pyvenv.

If we’d like to use tkinter, we get the following error:

$ python
>>> import tkinter
ImportError                               Traceback (most recent call last)
<ipython-input-1-b98d59735c04> in <module>()
----> 1 import tkinter

/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tkinter/ in <module>()
     36     from tkinter import _fix
---> 38 import _tkinter # If this fails your Python may not be configured for Tk
     39 TclError = _tkinter.TclError
     40 from tkinter.constants import *

ImportError: No module named '_tkinter'

First we check that we have the tkinter package installed and it’s in the Python module path.

For Python 3.4 there’s a port named py34-tkinter:

$ sudo port install py34-tkinter

The installed files are here:

$ port contents py34-tkinter

Port py34-tkinter contains:

However the module is not in the Python path (note the site-packages/ subdirectory):

$ python -c 'import sys; print(*sys.path, sep="\n")'


It seems that the py34-tkinter package should put the file one directory level higher. We can hack it by making a symlink:

$ TKMODULE=$(port contents py34-tkinter|grep
$ sudo ln -s $TKMODULE $(echo $TKMODULE|sed 's/site-packages\///')

If it’s ok, the tkinter module can be imported without any error:

$ python -m tkinter

Importing the module this way opens up a small testing GUI dialog.

Hope this helps!


Fork me on GitHub