[Tutor] FW: Embedding Python
Danny Yoo
dyoo@hkn.eecs.berkeley.edu
Mon, 29 Jul 2002 22:22:56 -0700 (PDT)
On Tue, 30 Jul 2002, BELSEY, Dylan wrote:
> I posted the below mail last week and haven't seen any replies on
> the topic so I am not sure if it got through or if the questions were
> out of the scope of this list. If it is out of scope, any suggestions
> to what list would be more appropriate.
Hi Dylan,
Yikes, I missed your original post!
There's a similar experience that some random guy named Guido stumbled
through while compiling the Demo/embed/ example that's included in the
source distribution:
http://mail.python.org/pipermail/python-dev/2000-July/005974.html
so I wouldn't worry about not getting this right the first time.
> > I am attempting to try and get the embedding of Python running on
> > my system (WinNT). I am using VC++ and I copied the code from "5.1
> > Very High Level Embedding" within "Extending and Embedding the Python
> > Interpreter" from the Python docs. I have also installed the latest
> > release of Python, version 2.3a0. The code from the documentation is
> > pasted below:
2.3a0 is still in alpha, so there may be other reasons why the example
isn't working for you yet; 2.3a0 may still yet have a buggy build
procedure. 2.2.1 is the latest stable release, so you may want to try
that instead.
> > #include <Python.h>
> >
> > int
> > main(int argc, char *argv[])
> > {
> > Py_Initialize();
> > PyRun_SimpleString("from time import time,ctime\n"
> > "print 'Today is',ctime(time())\n");
> > Py_Finalize();
> > return 0;
> > }
> >
> > It compiles OK but when I go to run it I get the following error:
> >
> > 'import site' failed; use -v for traceback
Hmmm... The embedding example shouldn't need to look for the site-wide
'site.py' module. Can you try it with '-v' to see what's going on?
My best guess so far is that, during the Py_Initialize() step, that some
symbols weren't compiled into your binary. For example, on Linux, the
following flags need to be used during compilation:
'-Xlinker -export-dynamic'
or else the 'import site' error occurs. Perhaps something similar needs
to be done in Visual C++? There's a section on Linking Requirements:
http://www.python.org/doc/current/ext/link-reqs.html
that might be relevant, although it only mentions Unix. The following
article might be helpful:
http://www.faqts.com/knowledge_base/view.phtml/aid/5325/fid/245
Unfortunately, I don't have Visual C++, so I can't experiment with this at
all. This may not be the best forum for getting a good answer to your
embedding question; you may want to try comp.lang.python or the
python-win32 list. Here's are links to both forums:
http://mail.python.org/mailman/listinfo/python-win32
http://mail.python.org/mailman/listinfo/python-list
Best of wishes to you!