Question

I've just installed the latest version of NLTK (2.0.4) from pip on OSX 10.8.2. This version os OSX doesn't come with X11 and I like it that way, I don't want to install it. However when I try importing nltk in python (2.7.2) an OSX dialog box pops up saying that I need to install X11??

This is probably due to Tkinter and the NLTK downloader (or something similar) and probably just a matter of setting some configuration option somewhere to not fall back on X11, I just don't know where to set that option.

There's a bug report for nltk-0.9.5 that the tk dependencies are required and this nltk can't be run an a server that doesn't have gui libraries, but that issue has been marked as resolved a long time ago.

Notice that I'm not trying to run the nltk downloader or anything else that should require a gui of any sorts, I'm simply trying to run import nltk when the dialog pops up.

The NLTK install docs don't give any indication that X11 is required.

So how do I get nltk to run on OSX 10.8 without X11?

Was it helpful?

Solution

It turns out that the problem indeed was Tkinter. I'm using the 64bit Mac version of EPDPython and for some reason they've decided to link Tk/Tcl to X11 instead of aqua or cocoa.

OsX 10.8 however comes preinstalled with the correct version of Tk/Tcl and the default python installation /usr/bin/python.2.7 works out of the box because it uses the correct windowing system for Tkinter. The solution is to just remove the wrong libraries from the EPD installation and it'll fall back on the correct system ones.

To try if the suggested fix will work run the system python with

$ /usr/bin/python2.7
Python 2.7.2 (default, Jun 20 2012, 16:23:33) 
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from Tkinter import *
>>>

that should complete without a problem (no dialog boxes), if so you're system python is fine, remove these

/Library/Frameworks/EPD64.framework/Versions/7.2/lib/libtcl8.5.dylib
/Library/Frameworks/EPD64.framework/Versions/7.2/lib/libtk8.5.dylib
/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/lib-dynload/_tkinter.so

and python should fall back on the system ones in

/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_tkinter.so
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top