[Twisted-Python] Trying to get twisted.protocols.amp to work with py2app...

I'm on a MacBook Pro running OS X 10.5.2 using py2app installed with the "easy" method in the py2app install docs. I'm trying to package a little pyglet+twisted (pyglet.org, twistedmatrix.com) project that I'm working on, and it _mostly_ works, except it keeps giving me the following error when I try to run the resulting app: ImportError: No module named amp Help!? I've done the following steps to try to debug the problem, with no success: * Noticed that the following imports DO work: from twisted.internet import reactor, task from twisted.internet.protocol import ClientCreator * Verified that I get the same error when running the app with the following import lines: import twisted.protocols.amp or from twisted.protocols import amp * Tried the following command-line variations without any variation in the error (although app sizes varied): python setup.py py2app --includes twisted.protocols python setup.py py2app --includes twisted.protocols.amp python setup.py py2app --use-pythonpath python setup.py py2app --use-pythonpath --include twisted.protocols.amp python setup.py py2app --use-pythonpath --include twisted.protocols.amp --graph python setup.py py2app --use-pythonpath --include twisted.protocols.amp -p twisted.protocols python setup.py py2app --use-pythonpath -p twisted.protocols python setup.py py2app --use-pythonpath -p twisted * Used the following py2applet-generated setup.py the whole time: """ This is a setup.py script generated by py2applet Usage: python setup.py py2app """ from setuptools import setup APP = ['running-man.py'] DATA_FILES = ['images'] OPTIONS = {'argv_emulation': True} setup( app=APP, data_files=DATA_FILES, options={'py2app': OPTIONS}, setup_requires=['py2app'], ) ~ Nathan

On 04:11 am, nathan.stocks@gmail.com wrote:
AMP itself isn't doing anything clever that I can see would confuse py2app. It's just a regular Python module with regular imports; no dynamic module loading; in fact, it's much less interesting than the core parts of Twisted which load various plugins. I don't have any experience with py2app, but I can guess at the problem - I know that OS X 10.5 ships with an incomplete installation of Twisted in some system location. Perhaps you've installed a complete version of Twisted elsewhere, but py2app is confused about the ordering of sys.path that you want, and is including the system location first. I am not aware of how this installation is incomplete - maybe it doesn't include AMP? However, this is only a vague understanding, I don't have a MacOS Python environment readily available to test with. Twisted might actually be packaged inside one of Apple's application, not on the system path, so this could be a red herring. Good luck investigating though, and please let us know your results when you discover what's going on!

Hi, took a quick look into the OS X 10.5 default twisted installation and indeed, there doesn't seem to be the amp.py module included in /System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/twisted/protocols Try http://twistedmatrix.com/trac/wiki/Packages#Leopard -p glyph@divmod.com napsal(a):

On Tue, Mar 4, 2008 at 5:08 AM, Petr Mifek <pm-twisted-python@anapol.cz> wrote:
Yes, I've taken all that into consideration from the start. As mentioned in my last post, I have a fully working version of Twisted 2.5. I followed that very FAQ back when I first installed it. I've explicitly told py2app to use my PYTHONPATH variable, and it actually copies twisted/protocols/amp.py into the app bundle. Yet the .app still fails with that import error about amp. Weird! ~ Nathan

On Tue, Mar 4, 2008 at 3:53 PM, Nathan <nathan.stocks@gmail.com> wrote:
Maybe when you actually run the .app it's finding the system-installed version of Twisted? -- Christopher Armstrong International Man of Twistery http://radix.twistedmatrix.com/ http://twistedmatrix.com/ http://canonical.com/

And the canonical way to locate that problem would be to add something like: import twisted.protocols print twisted.protocols.__file__ to your app, to see from where the twisted package is coming. Andreas Am Dienstag, den 04.03.2008, 16:26 -0500 schrieb Christopher Armstrong:

Now we're getting somewhere! Yes, even though py2app seems to be pulling in my Twisted 2.5 from /Library/Python/2.5/site-packages when the app is built, when the app is actually run it's finding the Leopard-default-installed Twisted 2.4 instead: /System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/twisted/protocols/__init__.pyc So, the next logical question would be: How do I get my script inside my .app to consider the libraries inside the .app first? You'd think that py2app would already be taking care of that... ~ Nathan

On Mar 4, 2008, at 6:50 PM, Nathan wrote:
This is a little inelegant (maybe even a lot inelegant), but when i've had issues with the system path that I couldn't fix (because I didn't have root, or was just in a hurry), I've just manipulated sys.path at the start of my code before I've imported any modules. -phil

On Tue, Mar 4, 2008 at 5:39 PM, Phil Christensen <phil@bubblehouse.org> wrote:
I'm fine with doing that, but how do you find the path you need to insert into sys.path? The amp.py that it includes is inside MyApp.app/Contents/Resources/lib/python2.5/site-packages.zip -- a ZIP file! Does sys.path support zip files?? sys.path.insert(0,'../Resources/lib/python/2.5/site-packages.zip/twisted') ?? ~ Nathan

Nathan wrote: [...]
regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/

On Wed, Mar 5, 2008 at 9:59 AM, Steve Holden <steve@holdenweb.com> wrote:
Perfect! 1) sys.path allows zip files (so that's how that works!) 2) sys.path allows relative paths 3) sys.path has the site-packages.zip entry near the end of sys.path Adding the following line to the top of my script WORKED! sys.path.insert(0,'../Resources/lib/python2.5/site-packages.zip') Thanks for all the help, everyone! ~ Nathan

On 05:32 pm, nathan.stocks@gmail.com wrote:
Adding the following line to the top of my script WORKED!
sys.path.insert(0,'../Resources/lib/python2.5/site-packages.zip')
I'd recommend reporting a bug against py2app for it to do this (or its equivalent) automatically; I'm glad you got this to work, but it would be a shame for every subsequent user of AMP (or other similarly mispackaged dependencies) on OS X to discover this bug and have to work around it in the same way. (By the way, what's the .app that you are p2app'ing actually do?)

On Wed, Mar 5, 2008 at 2:12 PM, <glyph@divmod.com> wrote:
(By the way, what's the .app that you are p2app'ing actually do?)
It's the client portion of a 2D game I'm making with my brother for fun. My coworkers help me test it out, but they don't have the whole environment (twisted, pyglet, etc.) setup, so I need to package it for them. I attached a screenshot if you're curious. Any resemblance to a popular 3D game is purely coincidental. ~ Nathan

Andreas Kostyrka wrote:
How would I be supposed to know what gentlemen do? ;-) regards Sreve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/

On Wed, Mar 5, 2008 at 2:31 PM, Steve Holden <steve@holdenweb.com> wrote:
Well ... for one, distinguished gentlemen don't use eggs ;-) -- \\\\\/\"/\\\\\\\\\\\ \\\\/ // //\/\\\\\\\ \\\/ \\// /\ \/\\\\ \\/ /\/ / /\/ /\ \\\ \/ / /\/ /\ /\\\ \\ / /\\\ /\\\ \\\\\/\ \/\\\\\/\\\\\/\\\\\\ d.p.s

On Mar 5, 2008, at 2:31 PM, Steve Holden wrote:
It's easy. "Gentlemen", when used in this context, means "someone who designs a packaging system without broad community input, and creates a buggy implementation that is somehow accepted into the language distribution, thus forcing developers all around the world to stick to their ill-defined standard." I remember it by using the mnemonic device SWDAPSWBCIACABITISAITLDTFDAAWTSTTIDS... -phil

On Wed, Mar 5, 2008 at 3:01 PM, Phil Christensen <phil@bubblehouse.org> wrote:
Please, let's not start a huge flamewar about eggs. -- Christopher Armstrong International Man of Twistery http://radix.twistedmatrix.com/ http://twistedmatrix.com/ http://canonical.com/

Am Mittwoch, den 05.03.2008, 15:01 -0500 schrieb Phil Christensen: Well, how buggy it is, is open to discussion. Clearly distutils becames quite nicer when upgraded to setuptools. But having no packaging format is not a solution either. I have no idea how long you've been doing Python but I do remember the times when most C language modules came without any build support (figure out the compiler call yourself, and enjoy), or Makefile fragements at best. So despite all potentially problematic aspects of distutils/setuptools/pypi, it's a vast improvement. (Compare pypi to the Vault of Parnassus and tell me that it is not an improvement) Andreas

Andreas Kostyrka wrote:
It's not an improvement. See how easy lying is? ;-) regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/

On 07:31 pm, steve@holdenweb.com wrote:
Eggs are something different; eggs can, in fact, be directories, as well as zip files. Zip files that you can import Python out of are just that - zip files :).

On Wed, 2008-03-05 at 18:41 +0100, Andreas Kostyrka wrote:
Oh so *that's* what eggs are. The sound you just heard was that of a lightbulb going on. -- Justin Warren <daedalus@eigenmagic.com>

On Tue, Mar 4, 2008 at 2:13 AM, <glyph@divmod.com> wrote:
I agree, which is yet another reason why it's so weird that amp doesn't work but the more complicated stuff does.
I installed Twisted 2.5 from source into /Library/Python/2.5/site-packages. I set PYTHONPATH to /Library/Python/2.5/site-packages as mentioned in the wiki. Had I not done that, AMP would have not been accessible period. As I mentioned above, I've done "python setup.py py2app --use-pythonpath" which is supposed to make py2app aware of the PYTHONPATH env variable. I've also tried adding "sys.path.insert(0,'/Library/Python/2.5/site-packages')" to the top of my script. I've also tried instructing py2app to include twisted.protocols.amp with "python setup.py py2app --use-pythonpath --include twisted.protocols.amp". In ALL cases (if I remember correctly), there exists a file twisted/protocols/amp.py INSIDE the .app bundle each time. Yet the import still fails when launching the .app. Weird! ~ Nathan

On 04:11 am, nathan.stocks@gmail.com wrote:
AMP itself isn't doing anything clever that I can see would confuse py2app. It's just a regular Python module with regular imports; no dynamic module loading; in fact, it's much less interesting than the core parts of Twisted which load various plugins. I don't have any experience with py2app, but I can guess at the problem - I know that OS X 10.5 ships with an incomplete installation of Twisted in some system location. Perhaps you've installed a complete version of Twisted elsewhere, but py2app is confused about the ordering of sys.path that you want, and is including the system location first. I am not aware of how this installation is incomplete - maybe it doesn't include AMP? However, this is only a vague understanding, I don't have a MacOS Python environment readily available to test with. Twisted might actually be packaged inside one of Apple's application, not on the system path, so this could be a red herring. Good luck investigating though, and please let us know your results when you discover what's going on!

Hi, took a quick look into the OS X 10.5 default twisted installation and indeed, there doesn't seem to be the amp.py module included in /System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/twisted/protocols Try http://twistedmatrix.com/trac/wiki/Packages#Leopard -p glyph@divmod.com napsal(a):

On Tue, Mar 4, 2008 at 5:08 AM, Petr Mifek <pm-twisted-python@anapol.cz> wrote:
Yes, I've taken all that into consideration from the start. As mentioned in my last post, I have a fully working version of Twisted 2.5. I followed that very FAQ back when I first installed it. I've explicitly told py2app to use my PYTHONPATH variable, and it actually copies twisted/protocols/amp.py into the app bundle. Yet the .app still fails with that import error about amp. Weird! ~ Nathan

On Tue, Mar 4, 2008 at 3:53 PM, Nathan <nathan.stocks@gmail.com> wrote:
Maybe when you actually run the .app it's finding the system-installed version of Twisted? -- Christopher Armstrong International Man of Twistery http://radix.twistedmatrix.com/ http://twistedmatrix.com/ http://canonical.com/

And the canonical way to locate that problem would be to add something like: import twisted.protocols print twisted.protocols.__file__ to your app, to see from where the twisted package is coming. Andreas Am Dienstag, den 04.03.2008, 16:26 -0500 schrieb Christopher Armstrong:

Now we're getting somewhere! Yes, even though py2app seems to be pulling in my Twisted 2.5 from /Library/Python/2.5/site-packages when the app is built, when the app is actually run it's finding the Leopard-default-installed Twisted 2.4 instead: /System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/twisted/protocols/__init__.pyc So, the next logical question would be: How do I get my script inside my .app to consider the libraries inside the .app first? You'd think that py2app would already be taking care of that... ~ Nathan

On Mar 4, 2008, at 6:50 PM, Nathan wrote:
This is a little inelegant (maybe even a lot inelegant), but when i've had issues with the system path that I couldn't fix (because I didn't have root, or was just in a hurry), I've just manipulated sys.path at the start of my code before I've imported any modules. -phil

On Tue, Mar 4, 2008 at 5:39 PM, Phil Christensen <phil@bubblehouse.org> wrote:
I'm fine with doing that, but how do you find the path you need to insert into sys.path? The amp.py that it includes is inside MyApp.app/Contents/Resources/lib/python2.5/site-packages.zip -- a ZIP file! Does sys.path support zip files?? sys.path.insert(0,'../Resources/lib/python/2.5/site-packages.zip/twisted') ?? ~ Nathan

Nathan wrote: [...]
regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/

On Wed, Mar 5, 2008 at 9:59 AM, Steve Holden <steve@holdenweb.com> wrote:
Perfect! 1) sys.path allows zip files (so that's how that works!) 2) sys.path allows relative paths 3) sys.path has the site-packages.zip entry near the end of sys.path Adding the following line to the top of my script WORKED! sys.path.insert(0,'../Resources/lib/python2.5/site-packages.zip') Thanks for all the help, everyone! ~ Nathan

On 05:32 pm, nathan.stocks@gmail.com wrote:
Adding the following line to the top of my script WORKED!
sys.path.insert(0,'../Resources/lib/python2.5/site-packages.zip')
I'd recommend reporting a bug against py2app for it to do this (or its equivalent) automatically; I'm glad you got this to work, but it would be a shame for every subsequent user of AMP (or other similarly mispackaged dependencies) on OS X to discover this bug and have to work around it in the same way. (By the way, what's the .app that you are p2app'ing actually do?)

On Wed, Mar 5, 2008 at 2:12 PM, <glyph@divmod.com> wrote:
(By the way, what's the .app that you are p2app'ing actually do?)
It's the client portion of a 2D game I'm making with my brother for fun. My coworkers help me test it out, but they don't have the whole environment (twisted, pyglet, etc.) setup, so I need to package it for them. I attached a screenshot if you're curious. Any resemblance to a popular 3D game is purely coincidental. ~ Nathan

Andreas Kostyrka wrote:
How would I be supposed to know what gentlemen do? ;-) regards Sreve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/

On Wed, Mar 5, 2008 at 2:31 PM, Steve Holden <steve@holdenweb.com> wrote:
Well ... for one, distinguished gentlemen don't use eggs ;-) -- \\\\\/\"/\\\\\\\\\\\ \\\\/ // //\/\\\\\\\ \\\/ \\// /\ \/\\\\ \\/ /\/ / /\/ /\ \\\ \/ / /\/ /\ /\\\ \\ / /\\\ /\\\ \\\\\/\ \/\\\\\/\\\\\/\\\\\\ d.p.s

On Mar 5, 2008, at 2:31 PM, Steve Holden wrote:
It's easy. "Gentlemen", when used in this context, means "someone who designs a packaging system without broad community input, and creates a buggy implementation that is somehow accepted into the language distribution, thus forcing developers all around the world to stick to their ill-defined standard." I remember it by using the mnemonic device SWDAPSWBCIACABITISAITLDTFDAAWTSTTIDS... -phil

On Wed, Mar 5, 2008 at 3:01 PM, Phil Christensen <phil@bubblehouse.org> wrote:
Please, let's not start a huge flamewar about eggs. -- Christopher Armstrong International Man of Twistery http://radix.twistedmatrix.com/ http://twistedmatrix.com/ http://canonical.com/

Am Mittwoch, den 05.03.2008, 15:01 -0500 schrieb Phil Christensen: Well, how buggy it is, is open to discussion. Clearly distutils becames quite nicer when upgraded to setuptools. But having no packaging format is not a solution either. I have no idea how long you've been doing Python but I do remember the times when most C language modules came without any build support (figure out the compiler call yourself, and enjoy), or Makefile fragements at best. So despite all potentially problematic aspects of distutils/setuptools/pypi, it's a vast improvement. (Compare pypi to the Vault of Parnassus and tell me that it is not an improvement) Andreas

Andreas Kostyrka wrote:
It's not an improvement. See how easy lying is? ;-) regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/

On 07:31 pm, steve@holdenweb.com wrote:
Eggs are something different; eggs can, in fact, be directories, as well as zip files. Zip files that you can import Python out of are just that - zip files :).

On Wed, 2008-03-05 at 18:41 +0100, Andreas Kostyrka wrote:
Oh so *that's* what eggs are. The sound you just heard was that of a lightbulb going on. -- Justin Warren <daedalus@eigenmagic.com>

On Tue, Mar 4, 2008 at 2:13 AM, <glyph@divmod.com> wrote:
I agree, which is yet another reason why it's so weird that amp doesn't work but the more complicated stuff does.
I installed Twisted 2.5 from source into /Library/Python/2.5/site-packages. I set PYTHONPATH to /Library/Python/2.5/site-packages as mentioned in the wiki. Had I not done that, AMP would have not been accessible period. As I mentioned above, I've done "python setup.py py2app --use-pythonpath" which is supposed to make py2app aware of the PYTHONPATH env variable. I've also tried adding "sys.path.insert(0,'/Library/Python/2.5/site-packages')" to the top of my script. I've also tried instructing py2app to include twisted.protocols.amp with "python setup.py py2app --use-pythonpath --include twisted.protocols.amp". In ALL cases (if I remember correctly), there exists a file twisted/protocols/amp.py INSIDE the .app bundle each time. Yet the import still fails when launching the .app. Weird! ~ Nathan
participants (9)
-
Andreas Kostyrka
-
Christopher Armstrong
-
Drew Smathers
-
glyph@divmod.com
-
Justin Warren
-
Nathan
-
Petr Mifek
-
Phil Christensen
-
Steve Holden