[Pythonmac-SIG] How to add appscript module to a pyobjc project?

Ned Deily nad at acm.org
Thu Nov 18 19:10:57 CET 2010


In article 
<AANLkTi=uZk73=srVAU9bF-na9q+n1LzEQF7-ygZqJne1 at mail.gmail.com>,
 Fur Yao <i at yaofur.com> wrote:
> In my app , I want to use "appscript" .
> 
> I use easy_install appscript , and it works well in my python script.
> 
> But when I build a Mac app in xcode , an error appears.
> 
> >>>
>    from appscript import app , k
> ImportError: No module named appscript
> >>>
> 
> Then I copy the appscript folder direct from
> "/Library/Python/2.6/site-packages/appscript-0.21.1-py2.6-macosx-10.6-universa
> l/"
> to
> the app's Resources folder.
> and I also copy aem mactypes.py osax.py
> 
> And it appears:
> 
> "ImportError: Bad magic number in
> /Users/Kebot/git/Giraffa/build/Debug/Giraffa.app/Contents/Resources/appscript/
> __init__.pyc"

Your Xcode project is apparently using a different version of Python 
than the one appscript was installed with.  If you are on OS X 10.6, you 
may have the Xcode target set for 10.5 instead of 10.6 and, thus, are 
using the Apple-supplied python2.5 in your project.

For example:

$ /usr/bin/python2.6 
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ma
cpath.pyc
$ /usr/bin/python2.5 
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ma
cpath.pyc
RuntimeError: Bad magic number in .pyc file

If you do need to support 10.5, try installing appscript with python2.5, 
too.

$ /usr/bin/easy_install-2.5 appscript

-- 
 Ned Deily,
 nad at acm.org



More information about the Pythonmac-SIG mailing list