Embedding, "import site", PYTHONHOME, and an old, old issue

Jim Hill jimhill at swcp.com
Mon Feb 12 13:27:06 EST 2007


Gabriel Genellina wrote:
>En Sat, 10 Feb 2007 03:57:05 -0300, Jim Hill <jimhill at swcp.com> escribió:
>
>> int routine() {
>>   Py_Initialize();
>>   ...
>>   }
>
>(Why routine() and not main()? Unfortunately you can't repeteadly  
>initialize/finalize the interpreter, you must do that only once.)

This is a small routine tucked off to the side of a fairly large
mostly-FORTRAN-with-some-C program.  I need to parse a slash-delimited
input file from a different program and fill up some arrays with the
results.  Rather than wrestle with FORTRAN's wretched file I/O I thought
I'd do it this way.

>Try this:
>PyRun_SimpleString("import sys; print sys.path");
>to see where Python expects to find its library (or call the Py_GetPath  
>function).

It returned a list of paths nearly identical to what the interactive
interpreter does -- it's on a different machine and too long to retype
here -- the interactive sys.path has an empty string as item 0, while
the embedded sys.path returns the interactive[1:n].

>You may need to call Py_SetProgramName (before Py_Initialize) so it can  
>find where the standard library resides.

Didn't do anything, alas.

>At least for testing purposes, you can copy your executable into the same  
>directory where Python is installed.

No can do -- it's not my machine and I don't have appropriate
privileges.  Thanks for trying to help me out but I'm on a crash
deadline and it looks like I'll be doing some C parsing.  Blech.


Jim
-- 

                 It's not "pretexting", it's "lying."



More information about the Python-list mailing list