Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 18th, 2005, 10:00 PM
Tim Daneliuk
Guest
 
Posts: n/a
Default Generating .pyc/.pyo from a make file

I use a makefile to create distribution tarballs of freestanding Python
programs and their documentation. I cannot seem to find the right
command line option to just generate a pyc/pyo file from the program
and then exit. If I use 'python -OOOO -c"import myprog"' it creates
the pyo file, but myprog starts up and keeps running.

IOW, I need a batch method for generating compiled python. I know it
exists, but I can't find it for some reason ...

TIA,
--
----------------------------------------------------------------------------
Tim Daneliuk tundra@tundraware.com
PGP Key: http://www.tundraware.com/PGP/

  #2  
Old July 18th, 2005, 10:00 PM
Roland Heiber
Guest
 
Posts: n/a
Default Re: Generating .pyc/.pyo from a make file

Tim Daneliuk wrote:[color=blue]
> I use a makefile to create distribution tarballs of freestanding Python
> programs and their documentation. I cannot seem to find the right
> command line option to just generate a pyc/pyo file from the program
> and then exit. If I use 'python -OOOO -c"import myprog"' it creates
> the pyo file, but myprog starts up and keeps running.
>
> IOW, I need a batch method for generating compiled python. I know it
> exists, but I can't find it for some reason ...
>
> TIA,[/color]
Hi,

take a look at http://docs.python.org/lib/module-compileall.html

HtH, Roland
  #3  
Old July 18th, 2005, 10:00 PM
Tim Daneliuk
Guest
 
Posts: n/a
Default Re: Generating .pyc/.pyo from a make file

Roland Heiber wrote:
[color=blue]
> Tim Daneliuk wrote:
>[color=green]
>> I use a makefile to create distribution tarballs of freestanding Python
>> programs and their documentation. I cannot seem to find the right
>> command line option to just generate a pyc/pyo file from the program
>> and then exit. If I use 'python -OOOO -c"import myprog"' it creates
>> the pyo file, but myprog starts up and keeps running.
>>
>> IOW, I need a batch method for generating compiled python. I know it
>> exists, but I can't find it for some reason ...
>>
>> TIA,[/color]
>
> Hi,
>
> take a look at http://docs.python.org/lib/module-compileall.html
>
> HtH, Roland[/color]

It does - thanks. One more question: Are pyc and pyo file portable
across operating systems? I suspect not since I generated a pyo
on a FreeBSD machine that will not run on a Win32 machine. I was
under the impression that "compiled" meant optimized byte code that
was portable across implementations, but it looks to not be the case...

--
----------------------------------------------------------------------------
Tim Daneliuk tundra@tundraware.com
PGP Key: http://www.tundraware.com/PGP/
  #4  
Old July 18th, 2005, 10:00 PM
Roland Heiber
Guest
 
Posts: n/a
Default Re: Generating .pyc/.pyo from a make file

Tim Daneliuk wrote:[color=blue]
> It does - thanks. One more question: Are pyc and pyo file portable
> across operating systems? I suspect not since I generated a pyo
> on a FreeBSD machine that will not run on a Win32 machine. I was
> under the impression that "compiled" meant optimized byte code that
> was portable across implementations, but it looks to not be the case...
>[/color]

Hi,

..pyc's should be, cause it's standard python-bytecode, if you use
massive optimizations it depends not on the os but on the underlying
cpu/architecture ...

So long, Roland
  #5  
Old July 18th, 2005, 10:00 PM
Steve Holden
Guest
 
Posts: n/a
Default Re: Generating .pyc/.pyo from a make file

Roland Heiber wrote:
[color=blue]
> Tim Daneliuk wrote:
>[color=green]
>> It does - thanks. One more question: Are pyc and pyo file portable
>> across operating systems? I suspect not since I generated a pyo
>> on a FreeBSD machine that will not run on a Win32 machine. I was
>> under the impression that "compiled" meant optimized byte code that
>> was portable across implementations, but it looks to not be the case...
>>[/color]
>
> Hi,
>
> ..pyc's should be, cause it's standard python-bytecode, if you use
> massive optimizations it depends not on the os but on the underlying
> cpu/architecture ...
>
> So long, Roland[/color]

You probably tried to use a bytecode file from *one* version of Python
with an interpreter of another version. Python actually checks the first
four bytes of the .pyc file for a compatible "magic number" before
accepting the file for execution.

regards
Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005 http://www.python.org/pycon/2005/
Steve Holden http://www.holdenweb.com/
  #6  
Old July 18th, 2005, 10:01 PM
Tim Daneliuk
Guest
 
Posts: n/a
Default Re: Generating .pyc/.pyo from a make file

Steve Holden wrote:
[color=blue]
> Roland Heiber wrote:
>[color=green]
>> Tim Daneliuk wrote:
>>[color=darkred]
>>> It does - thanks. One more question: Are pyc and pyo file portable
>>> across operating systems? I suspect not since I generated a pyo
>>> on a FreeBSD machine that will not run on a Win32 machine. I was
>>> under the impression that "compiled" meant optimized byte code that
>>> was portable across implementations, but it looks to not be the case...
>>>[/color]
>>
>> Hi,
>>
>> ..pyc's should be, cause it's standard python-bytecode, if you use
>> massive optimizations it depends not on the os but on the underlying
>> cpu/architecture ...
>>
>> So long, Roland[/color]
>
>
> You probably tried to use a bytecode file from *one* version of Python
> with an interpreter of another version. Python actually checks the first
> four bytes of the .pyc file for a compatible "magic number" before
> accepting the file for execution.
>
> regards
> Steve[/color]

Aha! Exactly ... and that makes perfect sense too. D'oh! I guess a better
distribution strategy would be to have the installation program generate the pyo
file at installation time...

Thanks -

--
----------------------------------------------------------------------------
Tim Daneliuk tundra@tundraware.com
PGP Key: http://www.tundraware.com/PGP/
  #7  
Old July 18th, 2005, 10:01 PM
Steve Holden
Guest
 
Posts: n/a
Default Re: Generating .pyc/.pyo from a make file

Tim Daneliuk wrote:
[color=blue]
> Steve Holden wrote:
>[color=green]
>> Roland Heiber wrote:
>>[color=darkred]
>>> Tim Daneliuk wrote:
>>>
>>>> It does - thanks. One more question: Are pyc and pyo file portable
>>>> across operating systems? I suspect not since I generated a pyo
>>>> on a FreeBSD machine that will not run on a Win32 machine. I was
>>>> under the impression that "compiled" meant optimized byte code that
>>>> was portable across implementations, but it looks to not be the case...
>>>>
>>>
>>> Hi,
>>>
>>> ..pyc's should be, cause it's standard python-bytecode, if you use
>>> massive optimizations it depends not on the os but on the underlying
>>> cpu/architecture ...
>>>
>>> So long, Roland[/color]
>>
>>
>>
>> You probably tried to use a bytecode file from *one* version of Python
>> with an interpreter of another version. Python actually checks the
>> first four bytes of the .pyc file for a compatible "magic number"
>> before accepting the file for execution.
>>
>> regards
>> Steve[/color]
>
>
> Aha! Exactly ... and that makes perfect sense too. D'oh! I guess a
> better
> distribution strategy would be to have the installation program generate
> the pyo
> file at installation time...
>
> Thanks -
>[/color]
That's what most sensible distributions do.

regards
Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005 http://www.pycon.org/
Steve Holden http://www.holdenweb.com/
  #8  
Old July 18th, 2005, 10:01 PM
vincent wehren
Guest
 
Posts: n/a
Default Re: Generating .pyc/.pyo from a make file

Tim Daneliuk wrote:[color=blue]
> Steve Holden wrote:
>[color=green]
>> Roland Heiber wrote:
>>[color=darkred]
>>> Tim Daneliuk wrote:
>>>[/color][/color]
> Aha! Exactly ... and that makes perfect sense too. D'oh! I guess a
> better
> distribution strategy would be to have the installation program generate
> the pyo
> file at installation time...
>
> Thanks -[/color]

Also, the *.py? files contain the full pathname of the *.py they have
been compiled from. Copying them to other path locations will give you
the wrong __file___ information in tracebacks.

--
Vincent Wehren

  #9  
Old July 18th, 2005, 10:01 PM
Roland Heiber
Guest
 
Posts: n/a
Default Re: Generating .pyc/.pyo from a make file

Roland Heiber wrote:[color=blue]
> Tim Daneliuk wrote:[color=green]
>> under the impression that "compiled" meant optimized byte code that[/color][/color]

You where right, i was totally mislead by "optimized" ... ;)

Greetings, Roland
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles