Re: [Pyobjc-dev] Failed to run the HotKey Example
Brought to you by:
ronaldoussoren
From: Ronald O. <ron...@ma...> - 2014-01-09 11:01:12
|
On 04 Jan 2014, at 05:30, Jake Wang <del...@gm...> wrote: > Thank you Ronald. > > I will try it again, and look forward to seeing if you can run it successfully. I’ve tested the example with a slight newer version of the example code (and an experimental version of PyObjC, but that shouldn’t matter here) and it works for me. I tested both with ‘python setup.py py2app -A’ and ‘python setup.py py2app’. I did have to ensure that the application was started in 32-bit mode, either by running from the Terminal as "arch -i386 dist/HotKey.app/Contents/MacOS/HotKey” or by by selecting “Open in 32-bit mode” in the Get Info popup in the Finder. The newer version is attached below and only changes the way code is imported, it no longer uses “from Cocoa import *” (that also shouldn’t affect to way the application is launched, but should result in a faster launching application). I really don’t understand why an alias build doesn’t work for you even though just running “python HotKey.py” does seem to find PyObjC (otherwise you’d have gotten an import error there as well, and instead of the error message from the AppKit framework). Are you really sure that you used the same python executable for running HotKey.py directly and for running “python setup.py py2app -A”? You could add “import sys; print(sys.prefix)” to the start of HotKey.py to make sure, that should print the same prefix in both ways of running the script. Ronald > > Jake > > > On Fri, Jan 3, 2014 at 10:51 PM, Ronald Oussoren <ron...@ma...> wrote: > Hi, > > This example like all pyobjc examples with a setup.py file needs to be run from an application bundle (run "python setup.py -A"). > > This particular example has some other restrictions (which aren't documented on the website right now): > > * It requires python 2.x because it uses the Carbon package that was removed in Python 3.0 > > * It requires a 32-bit build of python 2.x because the Carbon package is ancient and uses functions that Apple hasn't made available in 64-bit code. > > The last restriction makes using py2app harder, because the app bundle will happily try to run in 64-bit mode when you build using a python that supports 64-bit code. The easiest workaround is to disable 64-bit through the finder (for this application). > > I'm not sure why the application gives an ImportError exception when you try to run it. The usual problem is that the python you're using to run py2app is a different one than you expect (e.g. one without pyobjc installed), but that doesn't seem to be the problem here because you don't get an ImportError when running the script from the command-line. > > Ronald > > P.S. I haven't tried to run this example in a long while, I'll try to do so tonight. > > On Jan 03, 2014, at 03:02 PM, Jake Wang <del...@gm...> wrote: > >> Hi, >> >> I was trying to run the sample PyObjc HotKey example app downloaded from this link: http://pythonhosted.org/pyobjc/_downloads/PyObjCExample-HotKeyPython.zip >> >> (My environment: Mac OS X 10.8.5, Python 2.7.5) >> >> After I unpacked the file, I tried to: >> >> 1) run it via: >> >> python HotKey.py >> >> and got the following error: >> >> Traceback (most recent call last): >> File "HotKey.py", line 18, in <module> >> from Carbon.CarbonEvt import RegisterEventHotKey, GetApplicationEventTarget >> ImportError: cannot import name RegisterEventHotKey >> >> 2) run it in 32bit mode, as I thought this might only be supported in 32bit. >> >> arch -i386 python HotKey.py >> >> and got another error: >> >> 2014-01-03 21:57:41.083 Python[2047:f0b] No Info.plist file in application bundle or no NSPrincipalClass in the Info.plist file, exiting >> >> 3) Then I thought I might have to package it as an xx.app to run, then I executed the following command to package it: >> >> python setup.py py2app -A >> >> (also tried 'arch -i386 python setup.py py2app -A') >> >> The app couldn't be run, and then ran it from console, I got the following errors: >> >> Traceback (most recent call last): >> File "/Users/jiakuanwang/opensource/PyObjCExample-HotKeyPython/dist/HotKey.app/Contents/Resources/__boot__.py", line 69, in <module> >> _run() >> File "/Users/jiakuanwang/opensource/PyObjCExample-HotKeyPython/dist/HotKey.app/Contents/Resources/__boot__.py", line 62, in _run >> exec(compile(source, script, 'exec'), globals(), globals()) >> File "/Users/jiakuanwang/opensource/PyObjCExample-HotKeyPython/HotKey.py", line 16, in <module> >> from AppKit import * >> ImportError: No module named AppKit >> 2014-01-03 22:00:41.775 HotKey[2126:707] HotKey Error >> >> Is it possible to run it in some way? Thanks in advance! >> >> Thanks, >> Jake >> ------------------------------------------------------------------------------ >> Rapidly troubleshoot problems before they affect your business. Most IT >> organizations don't have a clear picture of how application performance >> affects their revenue. With AppDynamics, you get 100% visibility into your >> Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro! >> http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk >> _______________________________________________ >> Pyobjc-dev mailing list >> Pyo...@li... >> https://lists.sourceforge.net/lists/listinfo/pyobjc-dev > > ------------------------------------------------------------------------------ > Rapidly troubleshoot problems before they affect your business. Most IT > organizations don't have a clear picture of how application performance > affects their revenue. With AppDynamics, you get 100% visibility into your > Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro! > http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk_______________________________________________ > Pyobjc-dev mailing list > Pyo...@li... > https://lists.sourceforge.net/lists/listinfo/pyobjc-dev |