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

Nathan nathan.stocks at gmail.com
Tue Mar 4 15:49:49 EST 2008

On Tue, Mar 4, 2008 at 2:13 AM,  <glyph at divmod.com> wrote:
>  On 04:11 am, nathan.stocks at gmail.com wrote:
>  >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
>  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 agree, which is yet another reason why it's so weird that amp
doesn't work but the more complicated stuff does.

>  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?

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

More information about the Twisted-Python mailing list