Using Tkinter inside a virtualenv (hack)

Some instructions on how to use the Tkinter Python package, within a virtualenv.

Tkinter is usually installed on OSX trhough macports as a global package:

sudo port install py27-tkinter

Within a virtualenv the package will not be imported, as global packages are not included by default:

>>> import Tkinter
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/", line 39, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named _tkinter

The package consists of a single library ( that can be installed in the virtual environment, just by symlinking it into the virtualenv’s site_package directory:

workon <virtualenv>
ln -s /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ .

Yes, it’s kind of an hack, but it works.