Embedding Python's library as zip file

2011-05-04 Thread Wojtek Mamrak
Hello,

I spent a lot of time googling for a solution of this problem, with no
result.

I have a C++ application, in which I would like to embed Python interpreter.
I don't want to rely on an interpreter being installed on user machine,
instead I would like to distribute all the necessary files with my app.

As far as I understand, beside of my executable and Python.dll (I am using
Python27), I need to provide two folders:
 - DLLs,
 - Lib

If I place the Lib folder and the contents of the DLLs folder in a directory
of my executable, then everything seems to work.
However I would like to use a zipped Lib folder. Hence I made an archive
(which contains contents of Lib folder) called Python27.zip. Unfortunately
the app crashes during execution.
I assume the reason might be lack of zlib.pyd. Is that assumption correct?
If so, how to obtain it? If not, what am I doing wrong?

Thanks in advance
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Embedding Python's library as zip file

2011-05-05 Thread Wojtek Mamrak
Thanks for the reply!

> Can you import from zip files when running the Python.exe interpreter?
When I zip the folder "Lib" into Python27.zip and later rename it and
try to run the python.exe, I receive an error:
"Import error: no module named site"

> Is the zip file included in sys.path?  You might need to add this
> yourself after callying Py_Initialize().
Before renaming the "Lib" folder, the path to the python27.zip exists
in sys.path.

> Is there a top-level directory in the zip file that may be throwing
> the importer off?
I am testing all the cases so this is not the issue.

> Are you getting any sort of error message?
When I run my app, it crashes while calling Py_Initialize(). The
console closes suddenly.

Is it necessary to create zip archive using zipfile.PyZipFile?

regards


2011/5/5 Ian Kelly 
>
> On Wed, May 4, 2011 at 3:09 PM, Wojtek Mamrak  wrote:
> > Hello,
> >
> > I spent a lot of time googling for a solution of this problem, with no
> > result.
> >
> > I have a C++ application, in which I would like to embed Python interpreter.
> > I don't want to rely on an interpreter being installed on user machine,
> > instead I would like to distribute all the necessary files with my app.
> >
> > As far as I understand, beside of my executable and Python.dll (I am using
> > Python27), I need to provide two folders:
> >  - DLLs,
> >  - Lib
> >
> > If I place the Lib folder and the contents of the DLLs folder in a directory
> > of my executable, then everything seems to work.
> > However I would like to use a zipped Lib folder. Hence I made an archive
> > (which contains contents of Lib folder) called Python27.zip. Unfortunately
> > the app crashes during execution.
> > I assume the reason might be lack of zlib.pyd. Is that assumption correct?
> > If so, how to obtain it? If not, what am I doing wrong?
>
> I believe zlib.pyd is statically linked into python27.dll nowadays.
> Some things to check:
>
> Can you import from zip files when running the Python.exe interpreter?
> Is the zip file included in sys.path?  You might need to add this
> yourself after callying Py_Initialize().
> Is there a top-level directory in the zip file that may be throwing
> the importer off?
> Are you getting any sort of error message?
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Embedding Python's library as zip file

2011-05-05 Thread Wojtek Mamrak
> That means it's not finding it.  After startup, try adding the zip
> file to your sys.path and then do "import site" at the command line,
> and it should work.

Maybe I am missing the point, but I think I am not able to do this.
When I remove the "Lib" folder and try to run Python.exe, the python
console window closes rapidly, so that it is hard to read any message
displayed in it and obvioulsy I can't run any python command. Could
you clarify this please?


> What if you put the zip file in your
> PYTHONPATH environment variable?

I don't have it defined. Maybe it is because I have 2 different Python
interpreters installed.
After adding the PYTHONPATH, the Python.exe seems to run normally.
Unfortunately I am not able to import Image module (I am using it),
which is installed in site-packages/PIL.
This happens, because for some reason the site-packages directory is
not present in sys.path. After reading the site module description I
checked the sys.prefix and sys.exec_prefix, which are both empty, when
the Lib folder is loaded from the zip archive. Thats why site-packages
is not added to sys.path.
Of course I can add site-packages directory to the sys.path by myself
(yet I don't know why sys.prefix and sys.exec_prefix are empty),
however how to deal with the PYTHONPATH, which is required to load
site.py and hence has to be defined at the very beginning?


thanks for your help


2011/5/5 Ian Kelly :
> On Thu, May 5, 2011 at 4:55 AM, Wojtek Mamrak  wrote:
>> Thanks for the reply!
>>
>>> Can you import from zip files when running the Python.exe interpreter?
>> When I zip the folder "Lib" into Python27.zip and later rename it and
>> try to run the python.exe, I receive an error:
>> "Import error: no module named site"
>
> That means it's not finding it.  After startup, try adding the zip
> file to your sys.path and then do "import site" at the command line,
> and it should work.
>
>>> Are you getting any sort of error message?
>> When I run my app, it crashes while calling Py_Initialize(). The
>> console closes suddenly.
>
> Hm, that definitely seems odd.  What if you put the zip file in your
> PYTHONPATH environment variable?
>
>> Is it necessary to create zip archive using zipfile.PyZipFile?
>
> It shouldn't be.  It works for me (at least with Python.exe) creating
> the zip archive using 7-Zip.
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Embedding Python's library as zip file

2011-05-06 Thread Wojtek Mamrak
> Are you calling Py_SetProgramName?  That may help to set sys.prefix
> and sys.exec_prefix.  However, looking at site.py, it appears that
> it's only looking for proper directories.  I don't think it will be
> able to add a site-packages inside a zip archive at all; you will just
> have to add that yourself.

Yes, I have tried Py_SetProgramName, but I am even not sure what
argument (name, path?) should be passed to it and how it will affect
the application.


Some good news.
After simplifying my application I realized, that importing of modules
from the zip archive works well, I only have to add site-packages to
sys.path (it looks like "python27.zip/site-packages").

Unfortunately even though I can import Image package, something still
causes applications' sudden death. I will try to figure out what is
the reason of that. As I said, the only non-standard package I am
using is PIL.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PIL: The _imaging C module is not installed

2011-05-06 Thread Wojtek Mamrak
@Michel
use PIL downloaded from here: http://www.lfd.uci.edu/~gohlke/pythonlibs/

regards

2011/5/6 Christian Heimes :
> Am 06.05.2011 01:48, schrieb Michel Claveau - MVP:
>> Re!
>>
>> And why the problem no exist with PIL 1.1.6?  (only 1.1.7)
>> Is that the version 1.1.6 does not use these libraries?
>
> PIL 1.1.6 also uses its internal C library to speed things up.
>
> For Windows you should use the precompiled packages.
> http://www.pythonware.com/products/pil/ offers X86 Windows binaries for
> 1.1.7. You might run into a problem with 1.1.7 Windows binaries. The
> freetype C library references a debug CRT that is not available on all
> machines. You can easily patch the _imagingft.pyd file with a hex editor.
>
> Christian
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Embedding Python's library as zip file

2011-05-06 Thread Wojtek Mamrak
> I used py2exe in the past for that, see 
> http://www.py2exe.org/index.cgi/ShippingEmbedded

Thanks for the advice, py2exe seems to be a great tool.
Unfortunately the application stops executing at the same place. It
might be the case of PIL library, I found some entries about it on
py2exe site.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: NewBie Doubt in Python Thread Programming

2011-05-11 Thread Wojtek Mamrak
Is there any special reason you don't want to use QThread?
http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qthread.html#details

regards

2011/5/11 Chris Angelico :
> On Wed, May 11, 2011 at 7:08 PM, vijay swaminathan  wrote:
>> Sorry. My intention was not to send out a private message. when I chose
>> reply to all, I was confused if this would start as a new thread. so just
>> did a reply..
>
> No probs. If you just send your response to the list
> python-list@python.org. it'll get to everyone.
>
>> I have developed a GUI based on pyQT4 which has a run button. when I click
>> on run, it invokes a command prompt and runs a .bat file.
>>
>> Till the execution of .bat file is over, I want the run button on the GUI to
>> be disabled. so i thought of invoking the command prompt and running the
>> .bat file on a thread so that I could monitor the status of the thread
>> (assuming that the thread would be active till command prompt is active -
>> correct me if I'm wrong).
>
> Yes, but only if you use os.system().
>
>> Any flaw  in the logic? any other better ways of achieving this?
>>
>
> You'll find it easier to get an event at the end of it; simply have
> another line of code after the os.system() which will reenable the
> button.
>
> Chris Angelico
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: NewBie Doubt in Python Thread Programming

2011-05-11 Thread Wojtek Mamrak
2011/5/11 Chris Angelico :
> On Thu, May 12, 2011 at 1:16 AM, Wojtek Mamrak  wrote:
>> Is there any special reason you don't want to use QThread?
>> http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qthread.html#details
>
> Other than that QThread is part of QT and threading isn't, what are
> the advantages of QThread? Is it possible (safe) to manipulate QT
> objects - in this case, the button - from a thread other than the one
> that created them? (If not, that would be a good reason for using
> QThread, which will fire an event upon termination.)
>


QThread provides mechanism of signals and slots ("from" and "to" the
thread), which are used across all pyQt. Unfortunately it is not
possible to use any widget classes in the thread (direct quote from
the docs). On the other hand signals can fire methods from the main
thread (running the app'a main loop), so this is not a big deal.
The signals are:
- finished
- started
- terminated
It is possible to block the thread, make it sleep, check whether the
thread is running, and few others.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python drawing library?

2011-05-15 Thread Wojtek Mamrak
Yes, it is possible with use of PyQt.

2011/5/15 Rafael Durán Castañeda :
> On 15/05/11 01:01, OKB (not okblacke) wrote:
>>
>>        Is there any Python library for interactive drawing?  I've done
>> some googling but most searches for "drawing" lead me to libraries for
>> programmatic creation of shapes on some GUI canvas.  I'm looking for GUI
>> widgets that allow the user to draw with the mouse, like a paint
>> program, and let me get info about the drawing as its made (get color at
>> mouse location, etc.).  I'd prefer a wxPython solution, although any
>> Python solution would be better than none.
>>
>> Thanks,
>
> I'm not suere, but I think you should be able to do that using PyQt
> QPaintDevice.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list