How to distribute a python Tkinter GUI from one Mac to another
April 10, 2013 2:36 AM   Subscribe

I've been writing python software with Tkinter GUIs as a hobby for a while, but for the first time, I've made a some pieces of code that a few other people want to use. Unfortunately, I've been really frustrated by attempts to distribute the software because of incompatibility with Tcl/Tk installations on computers I'm distributing the software to. I'm on a Mac, and I'm distributing to other Macs at this point.

I've been using py2app to bundle the code, and I can easily get the apps to run on my machine, but it seems like the slightest version mismatch between the Tkinter that gets bundled and the Tcl/Tk version on the destination machine causes a fatal error. For example, I have tk 8.6.0 installed, abd Tkinter 2.7.3, but the .app that I made wouldn't run on a machine that had tk 8.5.12. It has worked on a computer where the Tcl/Tk installation matched mine, but I obviously can't guarantee that will be the case all the time.

Here's are my related questions:
1. Is there a way to somehow include Tcl/Tk with the py2app bundle so it doesn't depend on the destination machine having the right version?
2. Is there instead a good way to include multiple versions of Tkinter and have software attempt to import each of them until one of them is found to work?
3. Should I give up on doing this with Tkinter? Is there a GUI framework that is more "portable"? I know wxPython is not pure python either, so does that suffer the same issues?
4. Or am I asking the wrong questions here?
posted by Salvor Hardin to Computers & Internet (8 answers total) 3 users marked this as a favorite
 
*nix systems are absolutely insane about compatibility and dependencies. You'd think that one version of software from the next would be more or less compatible, but they aren't.

In the Linux world, most of the package managers have a way for software to specify what its dependancies are. In Fedora, if I do "yum install package" it figures out what other software the new package depends on and asks if it can install those for you.

I would expect that a .app would have a similar function, but how it works I don't know. Short of that, you have to just document what versions people have and make them install what is required.
posted by gjc at 2:48 AM on April 10, 2013


Have you thought about using Cocoa if it's for macs?
posted by empath at 3:02 AM on April 10, 2013


PyObjC
posted by empath at 3:03 AM on April 10, 2013


You could use an application like Packages (easy, free, GUI) or Apple's pkgbuild (more difficult, also free, CLI) to bundle your scripts together with Tcl/Tk .framework files that match your version requirements. Your installer places the frameworks in a folder of your choice (e.g., in /Library/Frameworks or ~/Library/Frameworks) where your Python scripts are directed to import them.
posted by Blazecock Pileon at 3:06 AM on April 10, 2013


If OSX ships with a version of Tcl/Tk/Tkinter you should develop with that one. And the best you can hope for is that if a machine has a newer version that the newer version has kept backwards compatibility with the older version. With the X.Y.Z Semantic Versioning you could hope that something built against X.Y.Z would work with X.Y.Z-1 or X.Y.Z+1 apart from any minor bugs you run into. In theory the API should stay the same across X.Y.*. If you're lucky a program built against X.Y.Z will work with X.Y+1.Z because X.Y+1 kept support for the older X.Y API. If you build against X.Y and try to run against X.Y-1, it will probably fail miserably.

You may be able to build the GUI modules statically or somehow have your libraries packaged up with your app, but that sometimes leads to even more pain. Your Tcl/Tk/Tkinter build may need a certain version of some PNG or JPG or other library that is on your system and then that library will happen to be the one that the target system has a different version of.

Does Python not have some sort of module dependency/packaging thing where you build your app and just have it declare that it needs the Tk modules and let the package manager install the appropriate Tk modules before installing your app? If you do it that way won't your app install the same on OSX/Windows/Linux without you having to worry about which versions of libraries are installed?
posted by zengargoyle at 3:20 AM on April 10, 2013


I know nothing about the app bundles that py2app creates, but on OSX you can include Foo.framework inside the application bundle and use it in preference to any other version of the framework present on your system. Can you get py2app to pull required frameworks in to the final bundle to avoid any versioning issues?
posted by russm at 3:28 AM on April 10, 2013 [1 favorite]


Definitely try to include any frameworks within your app bundle. You may also benefit from building your app on an older version of OS X—forwards compatibility tends to be a lot better than backwards.

Feel free to add more details, or to memail me. I have quite a bit of experience building things on OS X, and wouldn't mind helping.
posted by vasi at 3:27 PM on April 10, 2013


Response by poster: Thank you all for the advice - when I get a chance, I'll be looking into how to include the Tcl/Tk framework in the app bundle. If that doesn't work, I'll try using Packages. I'll report back.

empath - Thanks for pointing out PyObjC. I didn't do a very good job keeping the backend and frontend separate in this project, so it would be a significant undertaking to pull out the Tkinter and replace it with Cocoa, but I should probably start with Cocoa for the next project.

Thank you!
posted by Salvor Hardin at 7:42 PM on April 12, 2013


« Older Nice restaurants in or around Lafayette, CO   |   how do you get over your first "lover" Newer »
This thread is closed to new comments.