Python -O optimization?

1,113 views
Skip to first unread message

SK

unread,
Aug 2, 2010, 7:44:00 PM8/2/10
to PyInstaller
Hi,

Using the svn PyInstaller I can't get optimized python byte compiles
to work. I used to use a custom Makespec.py with
a.scripts+[('O','','OPTION')]
but that isn't working anymore. Adding the +[('O','','OPTION')] right
into the generated .spec files isn't working either.

When I go to build with either of those work-arounds (or neither)
using
python -O path\to\PyInstaller\Build.py myApp.spec
I get:
python optimization flags changed: rerun Configure.py with the same
[-O] option
Configure.py optimize=False, Build.py optimize=True
but Configure.py doesn't accept a -O option.

There is an environment variable that turns on Python optimization so
I suppose that would be a work around.

I realize that Python "optimization" is not of much value for
performance but it would still be nice to have a little more speed and
slightly smaller executables.

Ideas? Thanks!

SK

Giovanni Bajo

unread,
Aug 3, 2010, 7:04:12 AM8/3/10
to pyins...@googlegroups.com
On Mon, 2010-08-02 at 16:44 -0700, SK wrote:
> Hi,
>
> Using the svn PyInstaller I can't get optimized python byte compiles
> to work. I used to use a custom Makespec.py with
> a.scripts+[('O','','OPTION')]
> but that isn't working anymore. Adding the +[('O','','OPTION')] right
> into the generated .spec files isn't working either.
>
> When I go to build with either of those work-arounds (or neither)
> using
> python -O path\to\PyInstaller\Build.py myApp.spec
> I get:
> python optimization flags changed: rerun Configure.py with the same
> [-O] option
> Configure.py optimize=False, Build.py optimize=True
> but Configure.py doesn't accept a -O option.

What it really meant was to run "python -O Configure.py".
--
Giovanni Bajo :: ra...@develer.com
Develer S.r.l. :: http://www.develer.com

My Blog: http://giovanni.bajo.it
Last post: Compile-time Function Execution in D

Giovanni Bajo

unread,
Aug 3, 2010, 7:06:26 AM8/3/10
to pyins...@googlegroups.com
On Mon, 2010-08-02 at 16:44 -0700, SK wrote:
> Hi,
>
> Using the svn PyInstaller I can't get optimized python byte compiles
> to work. I used to use a custom Makespec.py with
> a.scripts+[('O','','OPTION')]
> but that isn't working anymore. Adding the +[('O','','OPTION')] right
> into the generated .spec files isn't working either.

This OPTION is used to switch the optimization flag within the runtime
interpreter. Usually, the flag affects only the way Python compiles the
bytecode (it generates .pyo instead of .pyc).

If you run PyInstaller with python -o Build.py, the generated file will
contain ONLY pyo files. At that point, even without the OPTION, it will
only execute those file.

So the OPTION is not necessary for what you were trying to achieve, as
far as I can tell.

SK

unread,
Aug 6, 2010, 12:46:47 AM8/6/10
to PyInstaller
Thanks Giovanni! Optimization is working now.

SK
Reply all
Reply to author
Forward
0 new messages