[Pythonmac-SIG] A question about embedding with Mac OS X Carbon

Tony Lownds tony@lownds.com
Fri, 12 Jul 2002 09:08:20 -0700


Hi Jay,

You have two options with Python 2.1 and 2.2. The first is to build a 
framework Python:

./configure --enable-framework; sudo make frameworkinstall

Then, in your app use the Python framework.

1. #include <Python/Python.h>

Python's Embedding docs always says #include "Python.h"; if your code 
uses that, add -I/Library/Frameworks/Python.framework/Headers to your 
compile command

2. compile and link with -F Python

This is not really "weak linking", good luck with that aspect (I 
haven't tried it)


The second option is to build a static libpython.a and link it right 
into your app. As I understand it this is useful when you won't need 
Python's standard lib, and not having a separate framework is a 
bonus. (Start by building python:
./configure; make; sudo make install)


Bill Fancher is working on providing a third option: a shared library 
that does not live in a framework.

-Tony

At 9:09 AM -0400 7/12/02, Jay Koutavas wrote:
>I've become a bit confused about the proper way to embed Python into 
>an OS X Carbon application. Perhaps someone could give a simple 
>step-by-step procedure to do this?
>
>Here's what I want to do:
>-------------------------
>Embed Python into my OS X Carbon application and access Python via a 
>command shell window of my own devising. I don't want to use the 
>SIOUX console at all. Python will be contained in a shared library. 
>If the library is present, my application is python enabled. If the 
>shared library is not present, no python (I do a weak link to the 
>shared library and determine at launch time if I'm going to provide 
>python support.) My python embed requires no mac-specific modules. 
>I'm using it for automated unit testing of my application's C++ data 
>model.
>
>What I ran into:
>---------------
>The embed demo suggests that I use PythonCore as my shared library, 
>and if I want to disable the SIOUX console, simply use the 
>PyMac_SetConsoleHandler(). However, the PyMac_SetConsoleHandler() 
>assumes you are using some form of GUSI, and in order to build the 
>PythonCore, you need GUSI.
>
>I don't want GUSI. I'm on OS X. OS X provides all GUSI could ever 
>provide, plus more.
>
>Additionally, I don't want to provide resources for configuring 
>Python, I'd rather configure python in the standard Unix way with 
>environment variables. I noted that macmain.c makes lots of resource 
>fork assumptions.
>
>The Question is:
>---------------
>So, I *think* this is the question I need to ask you all:
>
>``How does one generate a python shared library for Mac OS X Carbon 
>usage that doesn't require GUSI, nor does it use SIOUX? i.e. How to 
>do unix-style Python on an OS X box?''
>
>I'm really interested in Python on the Mac and have been following 
>this conference for years. Embedding Python on Mac OS X Carbon, I 
>think, should easily be equal to the ease of embedding Python on any 
>generic Unix box, agreed?
>
>... and perhaps that ease of embedding already exists and I simply 
>need a gentle "look right here!" and my confusion on this matter 
>will subside. :)
>
>Thank you very much to whom ever provides me the answer to this.
>
>
>Best,
>
>/Jay
>
>
>--
>'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
>   Jay Koutavas                         mailto:jay@heynow.com
>   Heynow Software                      http://www.heynow.com
>   Windham, New Hampshire, USA
>'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
>
>
>_______________________________________________
>Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
>http://mail.python.org/mailman/listinfo/pythonmac-sig