niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » python
Generating .pyc/.pyo from a make file
Post new topic   Reply to topic Page 1 of 1 [10 Posts] View previous topic :: View next topic
Author Message
Just
*nix forums addict


Joined: 24 Feb 2005
Posts: 54

PostPosted: Thu Feb 03, 2005 10:57 am    Post subject: Re: Generating .pyc/.pyo from a make file Reply with quote

In article <ctscc1$isf$1@news1.tilbu1.nb.home.nl>,
vincent wehren <vincent@visualtrans.de> wrote:

Quote:
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.

True.

Quote:
Copying them to other path locations will give you
the wrong __file___ information in tracebacks.

This is not 100% accurate: yes, the traceback shows the original source
file path, yet module.__file__ does point to the actual .pyc file it was
loaded from.

Just
Back to top
Roland Heiber
*nix forums beginner


Joined: 02 Mar 2005
Posts: 19

PostPosted: Thu Feb 03, 2005 6:55 am    Post subject: Re: Generating .pyc/.pyo from a make file Reply with quote

Roland Heiber wrote:
Quote:
Tim Daneliuk wrote:
under the impression that "compiled" meant optimized byte code that

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

Greetings, Roland
Back to top
Vincent Wehren
*nix forums addict


Joined: 23 Feb 2005
Posts: 58

PostPosted: Thu Feb 03, 2005 3:19 am    Post subject: Re: Generating .pyc/.pyo from a make file Reply with quote

Tim Daneliuk wrote:
Quote:
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
Back to top
Tim Daneliuk
*nix forums Guru Wannabe


Joined: 20 Mar 2005
Posts: 119

PostPosted: Wed Feb 02, 2005 11:38 pm    Post subject: Re: Generating .pyc/.pyo from a make file Reply with quote

Steve Holden wrote:

Quote:
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 tundra@tundraware.com
PGP Key: http://www.tundraware.com/PGP/
Back to top
Tim Daneliuk
*nix forums Guru Wannabe


Joined: 20 Mar 2005
Posts: 119

PostPosted: Wed Feb 02, 2005 11:16 pm    Post subject: Re: Generating .pyc/.pyo from a make file Reply with quote

Roland Heiber wrote:

Quote:
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 tundra@tundraware.com
PGP Key: http://www.tundraware.com/PGP/
Back to top
Steve Holden
*nix forums Guru


Joined: 22 Feb 2005
Posts: 1255

PostPosted: Wed Feb 02, 2005 10:39 pm    Post subject: Re: Generating .pyc/.pyo from a make file Reply with quote

Tim Daneliuk wrote:

Quote:
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/
Back to top
Steve Holden
*nix forums Guru


Joined: 22 Feb 2005
Posts: 1255

PostPosted: Wed Feb 02, 2005 10:22 pm    Post subject: Re: Generating .pyc/.pyo from a make file Reply with quote

Roland Heiber wrote:

Quote:
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/
Back to top
Roland Heiber
*nix forums beginner


Joined: 02 Mar 2005
Posts: 19

PostPosted: Wed Feb 02, 2005 10:21 pm    Post subject: Re: Generating .pyc/.pyo from a make file Reply with quote

Tim Daneliuk wrote:
Quote:
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
Back to top
Roland Heiber
*nix forums beginner


Joined: 02 Mar 2005
Posts: 19

PostPosted: Wed Feb 02, 2005 10:18 pm    Post subject: Re: Generating .pyc/.pyo from a make file Reply with quote

Tim Daneliuk wrote:
Quote:
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
Back to top
Tim Daneliuk
*nix forums Guru Wannabe


Joined: 20 Mar 2005
Posts: 119

PostPosted: Wed Feb 02, 2005 10:18 pm    Post subject: Generating .pyc/.pyo from a make file Reply with quote

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/
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [10 Posts] View previous topic :: View next topic
The time now is Thu Jan 08, 2009 10:13 pm | All times are GMT
navigation Forum index » Programming » python
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Running php file everyday on scheduled time sachin PHP 1 Fri Jul 21, 2006 12:49 pm
No new posts Regarding thesaurus iso file Srikanth modules 0 Fri Jul 21, 2006 10:42 am
No new posts make printer network available Johann Höchtl networking 0 Fri Jul 21, 2006 9:01 am
No new posts how can i get a file descriptor not used? mars system 0 Fri Jul 21, 2006 7:41 am
No new posts small GTK "Open file" dialog David Siroky Debian 0 Fri Jul 21, 2006 7:30 am

Watch Naruto Online | Remortgaging | Mobile Phones | Mortgage | Xbox Mod Chips
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.2340s ][ Queries: 20 (0.0938s) ][ GZIP on - Debug on ]