Friday, September 18, 2009

Native Mac PyGTK for Snow Leopard

I have just made a fresh build of native PyGTK for Mac on my new Snow Leopard install. It seems to be working - I have only tested my simple hello_pygtk.py script, and that works at least ;-)

You can grab the new build here: MacPyGTK_SnowLeopard_091809.dmg

Remember to follow the three simple instructions in README.txt in order to make it work. B.t.w., one has to be running Python in 32-bit mode for it to work. This can be done in two ways:
  1. By setting this environment variable VERSIONER_PYTHON_PREFER_32_BIT=yes
  2. By issuing this command (once): defaults write com.apple.versioner.python Prefer-32-Bit -bool yes
I would prefer setting the environment variable in a script starting my PyGTK application. That way I am changing as little as possible in the standard setup of the machine...

18 comments:

  1. Hi!

    I used your build with meld (http://meld.sourceforge.net/) and it works.

    It´s a bit ugly and the integration with the system is null but it works ok.

    Thanks.

    ReplyDelete
  2. Thanks! It was a nightmare to try to install GTK without direct internet connection.

    ReplyDelete
  3. Yes!

    You're my hero. I can finally use my pygtk apps on my mac, at last, since 10.6 upgrade. I was struggling with macport without results and was almost resignated to build it by hand when I found your package.

    I just had a problem with "import gtk" statement, that issued a "_glib.so: mach-o, but wrong architecture". The VERSIONER_PYTHON_PREFER_32_BIT instruction bit did not solve this problem. But I managed to find another solution by using "arch -i386 python" instead of "python", that will soon be turned into an alias in my profile.

    I have probably missed something in your instruction, but anyway, I'm too happy to get my apps back.

    Thank you *so* much.

    ReplyDelete
  4. Do you mind sharing your steps to build PyGTK?

    ReplyDelete
  5. Hi Ryanitus,

    take a look at this post: http://kedeligdata.blogspot.com/2009/03/pygtk-natively-on-mac.html

    I have simply used the jhbuild build script so it is pretty straightforward. There are sometimes small build errors but they can often be solved by a little googling :-)

    Best regards,
    Mads

    ReplyDelete
  6. do you thing clearlooks engine could be compiled to work with this?

    ReplyDelete
  7. Thanks for putting this together!

    Downloaded. Copied the MacPyGTK folder to /Developer. Set the 32bit flag. Set the PYTHONPATH to the folder specified.

    Running the included hello_pygtk.py fails with "ImportError: No module named pygtk"

    Are there any other requirements to getting this running on a clean 10.6 install? Do I need to build and install GTK from source first? Or is this package 100% inclusive of everything I should need to run a PyGTK app?

    ReplyDelete
  8. @Bryan: You need to copy the pygtk module to your Python interpreter's site-packages dir - or ts set the PYTHONPATH environment variable so that it points to the place where you keep your pkgkt module.

    I think this is described in the README file...

    Best regards,
    Mads

    ReplyDelete
  9. Hi,
    I tried building this and I had a few errors for wrong architecture, so I used the advice to build with arch -i386, but now I am getting a posix=_spawnp error saying Bad CPU type in executable. I looked online and this has to do with PPC's, but I have a new intel MBP running on 10.6.3.

    Any ideas?

    ReplyDelete
  10. It has been a long time since I have built it myself - so I'm sorry but I can't help you here. I had no problems building it...

    ReplyDelete
  11. When I try to run hello_pygtk.py I get an Import Error:
    ImportError: No module named pygtk
    I assume it has something to do with my path. In a terminal window I did this:
    % VERSIONER_PYTHON_PREFER_32_BIT=yes
    % PYTHONPATH=/Developer/MacPyGTK/inst/lib/python2.6/site-packages

    Am I doing it wrong?
    Thanks

    ReplyDelete
  12. Ahh OK I added the lines to my .profile and it no longer gets the import error but gets the architecture error.

    ReplyDelete
  13. Check your environment to see if you have actually set the correct variables. e.g.: echo $VERSIONER_PYTHON_PREFER_32_BIT

    If your PYTHONPATH and the prefer-32-bit thingy is set everything should work. If you want to set an environment variable that only "lives" for a single command, you need to specify the variable on the same line as you run the command. E.g.:

    VERSIONER_PYTHON_PREFER_32_BIT=yes python

    ReplyDelete
  14. Having issues with the import gtk. Says it cannot find module. I setup the path and the 32 bit. Double checked them. pygtk is getting imported with test script but not gtk

    ReplyDelete
  15. @Tobias: The problem is often that people have multiple versions of Python installed. Then when they e.g., place the Python modules in /Library/Python/2.5/site-packages/ they don't understand why the module can't be imported (which could be because their /usr/bin/python symlink is pointing to python2.4 or python2.6). Try to "hard code" the PYTHONPATH by issuing this command:

    PYTHONPATH=/path/to/whereever/you/installed/pygtk python

    That should do the trick I hope :-)

    ReplyDelete
  16. The download link for the library seems to be broken. When I clicked on the link I get a file not found error. Can you re-upload the library and update the link here? I really need this one as I am desperately trying to run tortoisehg gtk version on mac.

    ReplyDelete
  17. @Ashith: The link works again now.

    Be aware that this was built for an older version of Snow Leopard. I don't know whether it will work on the current version.

    ReplyDelete