Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.python
Re: Problem with sys.path when embedding Python3 in C
Krister Svanlund
3/23/2010 9:24:00 AM
On Tue, Mar 23, 2010 at 8:07 AM, Gabriel Genellina
<gagsl-py2@yahoo.com.ar> wrote:
> En Mon, 22 Mar 2010 18:19:49 -0300, Krister Svanlund
> <krister.svanlund@gmail.com> escribió:
>
>> Hi, I've recently begun experimenting with embedding python and i got
>> a small problem.
>>
>> The following line here is the ugly-hack I had to do to make it work,
>> nothing else I know of makes it possible to import modules from
>> startup directory. So my question is: Is there a prettier way to do
>> this?
>
> The startup directory is not included in the module search path - neither in
> your embedded version, nor in the standard interpreter (it's only included
> when running in interactive mode).
>
>>> PyRun_SimpleString("import sys\nsys.path.append(\"\")");
>
> If you really want the current directory in sys.path, use the getcwd
> function to obtain it. But make sure this is what you want - the directory
> containing the executable might be a better choice (at least more
> predictable).
> Note that Python already provides lots of ways to add directories to
> sys.path (the default search path (see site.py), per-user site directories
> (see PEP370), .pth files, the PYTHONPATH and PYTHONHOME environment
> variables, the Windows registry, other ways I forgot...) So I'd ask why do
> you want to add a non-standard one.
>
> In C code, you can alter the initial search path by setting
> Py_SetProgramName and Py_SetPythonHome. And you may even completely replace
> getpathp.c source file with your own.
>
> --
> Gabriel Genellina
>
> --
>
http://mail.python.org/mailman/listinfo/p...
>
The thing is that I want the application to be able to import modules
I've written, but yeah, the applications directory is what I want
rather than the cwd. I have tried Py_SetProgramName but haven't gotten
it to work or cause any change at all to the import behaviour. Could
you possibly provide som sort of example?
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: Problem with sys.path when embedding Python3 in C
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password