embedding wxpython issues on mac

Hi, I recently ported a linux/mac wxpython program over to visual studio. Unlike linux/mac I can’t depend on a user having a shell prompt available to invoke the python interpreter, so I created a simple executable for each script that uses the python embedding routines to start the interpreter. In visual studio these appear as another executable project, the user can select one for debugging, execution, or whatever.

// Setup python.
Py_Initialize();
PySys_SetArgv(argc,argv);

// Add hard coded paths.
PyRun_SimpleString(“import sys\n”);

// These lines added by CMAKE PyRun_SimpleString(“sys.path.append(r’/pathtobuilds/python’)\n”); PyRun_SimpleString(“sys.path.append(r’/pathtobuilds/lib’)\n”);

// Invoke the script.

PyRun_SimpleString( &buffer[0] );

These little programs work great in linux too since the user can run a single binary to start up the application instead of having to set the python path first. The problem is on Mac: starting the script up this way causes the familiar error:

This program needs access to the screen.
Please run with ‘pythonw’, not ‘python’, and only when you are logged

in on the main display of your Mac.

I’m not sure how to embed “pythonw” instead of the usual python libraries. From what I can tell “pythonw” is linked to the same libraries as “python”, so there must be an API difference. Does anyone have an idea? I am using 2.4.8 and the default leopard libraries.

-Thanks

Just to be clear -- you are embedding python in a C/C++ app, correct?

These little programs work great in linux too since the user can run a single binary to start up the application instead of having to set the python path first.

If that's the only reason, why not a simple shell script to start the app??

The problem is on Mac: starting the script up this way causes the familiar error:

This program needs access to the screen.
Please run with 'pythonw', not 'python', and only when you are logged
in on the main display of your Mac.

The difference is that on the Mac, in order to access the GUI, the application needs to be started in a particular way. pythonw does this for you (I think the core "python" does in recent versions, actually, so they are the same). py2app also starts up with a stub that starts u the right way.

I'm not sure how to embed "pythonw" instead of the usual python libraries.

So you don't need pythonw, but as your app is the host, it needs to register itself with the window manager first. Sorry I don't know how to do that, I've always used pythonw, py2app, or wxWidgets, all of which do it for me. It may be possible to just put your app inside an OS-X application bundle, which you want to do anyway, so that you get a nifty point and click-y app with an icon, etc.

An application bundle is simply a directory with a particular structure.

-CHB

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov