472,780 Members | 1,822 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,780 software developers and data experts.

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 tu****@tundraware.com
PGP Key: http://www.tundraware.com/PGP/

Jul 18 '05 #1
8 4194
Tim Daneliuk wrote:
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,

Hi,

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

HtH, Roland
Jul 18 '05 #2
Roland Heiber wrote:
Tim Daneliuk wrote:
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,


Hi,

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

HtH, Roland


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 tu****@tundraware.com
PGP Key: http://www.tundraware.com/PGP/
Jul 18 '05 #3
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
Jul 18 '05 #4
Roland Heiber wrote:
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


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/
Jul 18 '05 #5
Steve Holden wrote:
Roland Heiber wrote:
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

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


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 tu****@tundraware.com
PGP Key: http://www.tundraware.com/PGP/
Jul 18 '05 #6
Tim Daneliuk wrote:
Steve Holden wrote:
Roland Heiber wrote:
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


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

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 -

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/
Jul 18 '05 #7
Tim Daneliuk wrote:
Steve Holden wrote:
Roland Heiber wrote:
Tim Daneliuk wrote:

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 -


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

Jul 18 '05 #8
Roland Heiber wrote:
Tim Daneliuk wrote:
under the impression that "compiled" meant optimized byte code that


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

Greetings, Roland
Jul 18 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: edykstra | last post by:
Hello, If you point your browser to this page, http://prdownloads.sourceforge.net/vnc-tight/tightvnc-1.2.9_x86_viewer.zip?use_mirror=umn the server sends you the HTML page, and very soon...
3
by: skn | last post by:
Hello., Does the python compiler provide an option to generate a .pyo(optimized byte code file) from a .py (source file)? For generating .pyc I know that I only have to pass the source file...
3
by: Mike Kennedy | last post by:
I have an XML Snippet <?xml version="1.0" encoding="UTF-8"?> and when I convert the entire xml file to a DOM and then generate a new file from the DOM, results in <?xml version="1.0"?>. Any...
3
by: daniele.balducci | last post by:
Hi All, I'm generating XLS files from ASP(.Net) code using the usual code chunks ... Response.ContentType = "application/vnd.ms-excel" Response.AppendHeader("Content-Disposition", "attachment;...
2
by: Mike | last post by:
I'm trying to generate a shortcut file from VB. The code below is a cutdown version of some code I found on the net that is supposed to do the job The compiler complains about "WshShell" in the...
0
by: manas589 | last post by:
Hi Can any one tell me how to use binding.xml while generating castor bean from an xsd file. i have one xsd file where two element are conflicting. so i thought to use binding file while...
2
by: bizt | last post by:
Hi, Is it possible to obtain the width/ height of an image when that image is dyanically created using a PHP script and passing GET attributes. For example: <img...
7
by: Nathan Sokalski | last post by:
I am an ASP.NET developer, and Visual Studio 2005 seems to have stopped declaring the controls that I add in the *.designer.vb files, therefore forcing me to manually add them before I can use them...
1
by: Nathan Sokalski | last post by:
Visual Studio 2005 recently stopped generating the *.designer.vb files for my *.aspx and *.ascx files. I am using Service Pack 1, and do not believe I did anything differently than normal prior to...
1
by: csharpula csharp | last post by:
Hello, I need to generate cs files from XSD files. I would like to do it automatically. What is the best way to do it? Is it better be done with PreBuild inside VS (before compilation) or to...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.