tags:

views:

56

answers:

2

I am distributing an app that uses the Python/C API. I have all standard python modules in python31.zip which is basically an archive of the Lib folder in the python install directory. Here is the problem - most common modules like sys and io work fine. BUT tkinter does not. I get an error "cannot find module _tkinter". I really need tkinter in my project. I'm using Windows if that helps.

+1  A: 

why don't you use py2exe to bundle your application as an executable? It should take care of all the dependencies, and will include whatever you need.

Anurag Uniyal
Because the app is not python based. Its C++ based and uses python to add scripting support.
George Edison
+1  A: 

I don't the best way to bundle tkinter with your app, but I do know why you're getting the error you are. The relevant section of the zipimport module documentation:

Any files may be present in the ZIP archive, but only files .py and .py[co] are available for import. ZIP import of dynamic modules (.pyd, .so) is disallowed. Note that if an archive only contains .py files, Python will not attempt to modify the archive by adding the corresponding .pyc or .pyo file, meaning that if a ZIP archive doesn’t contain .pyc files, importing may be rather slow.

The module _tkinter is a c-extension / shared library. It can't be imported from a zip file.

Matt Anderson
Ahhh. That explains a few things. What dll/pyd file is responsible for tkinter?
George Edison