Re: embedded python in c++ packaging

2008-03-25 Thread Furkan Kuru
Sorry for long delay,

I've tried below code (Setting pythonpath environment variable)
and then initialize python interpreter but the embedded python interpreter
did not get the newly assigned PYTHONPATH.
I ve looked at the sys.path in python code (that is run by the embedded
interpreter) and it behaved according to older pythonpath.

Setting environment variable seemed to be correct.
Does py_initialize run in another thread so it starts before setting the
environment var?

// add custom plib.zip archive to pythonpath

if(!::getenv("PYTHONPATH"))

{

::putenv("PYTHONPATH=.;.\\plib.zip");

}

else ::putenv("PYTHONPATH=%PYTHONPATH%;.\\plib.zip");

std::cout << "PYTHONPath Set to: " << ::getenv("PYTHONPATH") << std::endl <<
"And Again: ";

system("echo %PYTHONPATH%");

Py_Initialize();



Regards,

On Fri, Feb 8, 2008 at 2:08 AM, Bronner, Gregory <[EMAIL PROTECTED]>
wrote:

>  I've done this the rather old-fashioned way.
>
> Basically, what I do is:
>
> Step 1:
>
> Embed Python:
>   if(!::getenv("PYTHONHOME"))
>   {
>  ::putenv("PYTHONHOME=");
>   }
>   if(!::getenv("PYTHONPATH"))
>   {
>  ::putenv("PYTHONPATH=.");
>   }
>
>   Py_SetProgramName("leaktester");
>   Py_InitializeEx(0);
>   init_memoryhoginterface();  // This initializes your SWIG module
>   PyRun_SimpleString("print 'HELLO FROM PYTHON'");  //<--- OR you can do
> something else here like run a file
>
>
> Step 2:
> Extend python to talk back to your C++ code.
> I use one giant SWIG module (see init function above)
>
> SWIG allows you to finely control what you expose to python, so you don't
> wind up exposing the whole C++ API.
>
>
>
>
>
>
>
>
>
>  --
> *From:* Furkan Kuru [mailto:[EMAIL PROTECTED]
> *Sent:* Thursday, February 07, 2008 6:06 PM
> *To:* python-list@python.org
> *Subject:* Re: embedded python in c++ packaging
>
>   I do not have access to my development machine right now.
> but is it enough adding just a simple line at the top of my main python
> file 'sys.path.append("modules.zip")' before importing any other modules?
>
> On 2/7/08, Gabriel Genellina <[EMAIL PROTECTED]> wrote:
> >
> > En Thu, 07 Feb 2008 16:18:57 -0200, Joshua Kugler <[EMAIL PROTECTED]>
> > escribió:
> > > Furkan Kuru wrote:
> > >>
> > >> I have been developing an application in C++ that embeds Python
> > >> interpreter. It takes advantage of too many modules from Python.
> > >> When I want to package this application, I need to add too many files
> > >> (.pyc) from Python/lib folder together with Python25.dll.
> > >> Is there a way to pack these .pyc files to a zip file and redirect
> > >> Python25.dll to that zip file?
> > >
> > > That is effectively what py2exe does with the modules required by the
> > > main
> > > application.  It takes all the required modules and puts them in a
> > > library.zip file.  You might take a look at how it does it.
> >
> > Using py2exe has an additional advantage, it recursively scans all
> > modules
> > looking for dependencies.
> > Once you know the required set of modules, you can bundle them in a .zip
> > file and add its full path into sys.path (the absolute path including
> > filename and .zip extension). Python does look into the .zip searching
> > for
> > modules.
> >
> > --
> > Gabriel Genellina
> >
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> >
>
>
>
> --
> Furkan Kuru
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> - - - - - - - This message is intended only for the personal and
> confidential use of the designated recipient(s) named above. If you are not
> the intended recipient of this message you are hereby notified that any
> review, dissemination, distribution or copying of this message is strictly
> prohibited. This communication is for information purposes only and should
> not be regarded as an offer to sell or as a solicitation of an offer to buy
> any financial product, an official confirmation of any transaction, or as an
> official statement of Lehman Brothers. Email transmission cannot be
> guaranteed to be secure or error-free. Therefore, we do not represent that
> this information is complete or accurate and it should not be relied upon as
> such. All information is subject to change without notice.  IRS
> Circular 230 Disclosure: Please be advised that any discussion of U.S. tax
> matters contained within this communication (including any attachments) is
> not intended or written to be used and cannot be used for the purpose of (i)
> avoiding U.S. tax related penalties or (ii) promoting, marketing or
> recommending to another party any transaction or matter addressed herein.




-- 
Furkan Kuru
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: embedded python in c++ packaging

2008-02-07 Thread Gabriel Genellina
En Thu, 07 Feb 2008 21:05:46 -0200, Furkan Kuru <[EMAIL PROTECTED]>  
escribió:

> I do not have access to my development machine right now.
> but is it enough adding just a simple line at the top of my main python  
> file
> 'sys.path.append("modules.zip")' before importing any other modules?

Almost. Some imports (site, warnings, os...) are done when Py_Initialize  
is executed, before there is a chance of modifying sys.path. You'll have  
to modify the environment (PYTHONPATH var) or look at how py2exe does  
that. Or use the name pythonXX.zip, which is already in sys.path (see PEP  
273 http://www.python.org/dev/peps/pep-0273/ )

-- 
Gabriel Genellina

-- 
http://mail.python.org/mailman/listinfo/python-list


RE: embedded python in c++ packaging

2008-02-07 Thread Bronner, Gregory
I've done this the rather old-fashioned way.
 
Basically, what I do is:
 
Step 1:
 
Embed Python:
  if(!::getenv("PYTHONHOME"))
  {
 ::putenv("PYTHONHOME=");
  }
  if(!::getenv("PYTHONPATH"))
  {
 ::putenv("PYTHONPATH=.");
  }
  
  Py_SetProgramName("leaktester");
  Py_InitializeEx(0);
  init_memoryhoginterface();  // This initializes your SWIG module 
  PyRun_SimpleString("print 'HELLO FROM PYTHON'");  //<--- OR you can do 
something else here like run a file
 
 
Step 2: 
Extend python to talk back to your C++ code. 
I use one giant SWIG module (see init function above)
 
SWIG allows you to finely control what you expose to python, so you don't wind 
up exposing the whole C++ API.
 
 

 
 
 
 
 



From: Furkan Kuru [mailto:[EMAIL PROTECTED] 
Sent: Thursday, February 07, 2008 6:06 PM
To: python-list@python.org
Subject: Re: embedded python in c++ packaging


I do not have access to my development machine right now.
but is it enough adding just a simple line at the top of my main python file 
'sys.path.append("modules.zip")' before importing any other modules?
 
On 2/7/08, Gabriel Genellina <[EMAIL PROTECTED]> wrote: 

En Thu, 07 Feb 2008 16:18:57 -0200, Joshua Kugler <[EMAIL PROTECTED]>
escribió:
> Furkan Kuru wrote:
>>
>> I have been developing an application in C++ that embeds Python
>> interpreter. It takes advantage of too many modules from Python.
>> When I want to package this application, I need to add too many files
>> (.pyc) from Python/lib folder together with Python25.dll.
>> Is there a way to pack these .pyc files to a zip file and redirect
>> Python25.dll to that zip file?
>
> That is effectively what py2exe does with the modules required by the
> main
> application.  It takes all the required modules and puts them in a
> library.zip file.  You might take a look at how it does it.

Using py2exe has an additional advantage, it recursively scans all 
modules
looking for dependencies.
Once you know the required set of modules, you can bundle them in a .zip
file and add its full path into sys.path (the absolute path including
filename and .zip extension). Python does look into the .zip searching 
for
modules.

--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list





-- 
Furkan Kuru 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
- - - -

This message is intended only for the personal and confidential use of the 
designated recipient(s) named above.  If you are not the intended recipient of 
this message you are hereby notified that any review, dissemination, 
distribution or copying of this message is strictly prohibited.  This 
communication is for information purposes only and should not be regarded as an 
offer to sell or as a solicitation of an offer to buy any financial product, an 
official confirmation of any transaction, or as an official statement of Lehman 
Brothers.  Email transmission cannot be guaranteed to be secure or error-free.  
Therefore, we do not represent that this information is complete or accurate 
and it should not be relied upon as such.  All information is subject to change 
without notice.


IRS Circular 230 Disclosure:
Please be advised that any discussion of U.S. tax matters contained within this 
communication (including any attachments) is not intended or written to be used 
and cannot be used for the purpose of (i) avoiding U.S. tax related penalties 
or (ii) promoting, marketing or recommending to another party any transaction 
or matter addressed herein.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: embedded python in c++ packaging

2008-02-07 Thread Furkan Kuru
I do not have access to my development machine right now.
but is it enough adding just a simple line at the top of my main python file
'sys.path.append("modules.zip")' before importing any other modules?

On 2/7/08, Gabriel Genellina <[EMAIL PROTECTED]> wrote:
>
> En Thu, 07 Feb 2008 16:18:57 -0200, Joshua Kugler <[EMAIL PROTECTED]>
> escribió:
> > Furkan Kuru wrote:
> >>
> >> I have been developing an application in C++ that embeds Python
> >> interpreter. It takes advantage of too many modules from Python.
> >> When I want to package this application, I need to add too many files
> >> (.pyc) from Python/lib folder together with Python25.dll.
> >> Is there a way to pack these .pyc files to a zip file and redirect
> >> Python25.dll to that zip file?
> >
> > That is effectively what py2exe does with the modules required by the
> > main
> > application.  It takes all the required modules and puts them in a
> > library.zip file.  You might take a look at how it does it.
>
> Using py2exe has an additional advantage, it recursively scans all modules
> looking for dependencies.
> Once you know the required set of modules, you can bundle them in a .zip
> file and add its full path into sys.path (the absolute path including
> filename and .zip extension). Python does look into the .zip searching for
> modules.
>
> --
> Gabriel Genellina
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Furkan Kuru
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: embedded python in c++ packaging

2008-02-07 Thread Gabriel Genellina
En Thu, 07 Feb 2008 16:18:57 -0200, Joshua Kugler <[EMAIL PROTECTED]>  
escribió:
> Furkan Kuru wrote:
>>
>> I have been developing an application in C++ that embeds Python
>> interpreter. It takes advantage of too many modules from Python.
>> When I want to package this application, I need to add too many files
>> (.pyc) from Python/lib folder together with Python25.dll.
>> Is there a way to pack these .pyc files to a zip file and redirect
>> Python25.dll to that zip file?
>
> That is effectively what py2exe does with the modules required by the  
> main
> application.  It takes all the required modules and puts them in a
> library.zip file.  You might take a look at how it does it.

Using py2exe has an additional advantage, it recursively scans all modules  
looking for dependencies.
Once you know the required set of modules, you can bundle them in a .zip  
file and add its full path into sys.path (the absolute path including  
filename and .zip extension). Python does look into the .zip searching for  
modules.

-- 
Gabriel Genellina

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: embedded python in c++ packaging

2008-02-07 Thread Joshua Kugler
Furkan Kuru wrote:
> Hello,
> 
> I have been developing an application in C++ that embeds Python
> interpreter. It takes advantage of too many modules from Python.
> When I want to package this application, I need to add too many files
> (.pyc) from Python/lib folder together with Python25.dll.
> Is there a way to pack these .pyc files to a zip file and redirect
> Python25.dll to that zip file?

That is effectively what py2exe does with the modules required by the main
application.  It takes all the required modules and puts them in a
library.zip file.  You might take a look at how it does it.

j

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: embedded python in c++ packaging

2008-02-07 Thread Warren Myers
The Python byte-code files are already pretty dense, so compressing them
further is unlikely to work if you try to put them in a zip.

WMM

On Feb 7, 2008 11:39 AM, Furkan Kuru <[EMAIL PROTECTED]> wrote:

> Hello,
>
> I have been developing an application in C++ that embeds Python
> interpreter.
> It takes advantage of too many modules from Python.
> When I want to package this application, I need to add too many files
> (.pyc) from Python/lib folder together with Python25.dll.
> Is there a way to pack these .pyc files to a zip file and redirect
> Python25.dll to that zip file?
>
> Thanks in advance.
>
> --
> Furkan Kuru
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
http://warrenmyers.com
"God may not play dice with the universe, but something strange is going on
with the prime numbers." --Paul Erdős
"It's not possible. We are the type of people who have everything in our
favor going against us." --Ben Jarhvi, Short Circuit 2
-- 
http://mail.python.org/mailman/listinfo/python-list

embedded python in c++ packaging

2008-02-07 Thread Furkan Kuru
Hello,

I have been developing an application in C++ that embeds Python interpreter.
It takes advantage of too many modules from Python.
When I want to package this application, I need to add too many files (.pyc)
from Python/lib folder together with Python25.dll.
Is there a way to pack these .pyc files to a zip file and redirect
Python25.dll to that zip file?

Thanks in advance.

-- 
Furkan Kuru
-- 
http://mail.python.org/mailman/listinfo/python-list