why are eggs full of .pyc files?

125 views
Skip to first unread message

qvx

unread,
Mar 28, 2006, 2:34:49 PM3/28/06
to TurboGears
I'm just curious. Why are 0.9a2 eggs full of .pyc files?

Karl Guertin

unread,
Mar 28, 2006, 3:07:02 PM3/28/06
to turbo...@googlegroups.com
On 3/28/06, qvx <qvx...@gmail.com> wrote:
> I'm just curious. Why are 0.9a2 eggs full of .pyc files?

pyc files are the bytecode complied version of normal .py files.
They're kept around so that the interpreter doesn't have to re-parse
the file every time it tries to load a module. Since eggs are not
usually intended to be worked with directly, it makes sense to
bytecode compile the source files in order to make module loading
faster.

At least, that's why I think eggs would be full of .pyc files. That
and the million messages 'bytecode compiling foo.py' when you
bdist_egg.

qvx

unread,
Mar 29, 2006, 4:40:31 AM3/29/06
to TurboGears
I know what pyc files are. I was thinking that they are maybe needed
because egg can be installed as zip archive so there is no place for
Python to put the resulting pcy files.

Dennis Brakhane

unread,
Mar 29, 2006, 9:29:54 AM3/29/06
to turbo...@googlegroups.com
- "Why can't she have 'egg, bacon, .pyc and sausage'"?
- "That's got .pyc in it!"
- "Hasn't got as much as '.pyc, egg, sausage and .pyc', has it?"

Sorry, I just couldn't resist! :-)

Jorge Godoy

unread,
Mar 29, 2006, 11:04:24 AM3/29/06
to turbo...@googlegroups.com
"Dennis Brakhane" <brak...@googlemail.com> writes:

No problem... But hey, is there any apple.py there? :-P

--
Jorge Godoy <jgo...@gmail.com>

Jorge Vargas

unread,
Mar 29, 2006, 5:13:14 PM3/29/06
to turbo...@googlegroups.com



On 3/28/06, Karl Guertin <gray...@gmail.com> wrote:

now back to the real question. 

At least, that's why I think eggs would be full of .pyc files. That
and the million messages 'bytecode compiling foo.py' when you
bdist_egg.

yes but i think that will optimice for your machine.

also aren't .pyc files platform dependant?



Tim Lesher

unread,
Mar 30, 2006, 4:42:23 AM3/30/06
to TurboGears
> yes but i think that will optimice for your machine.

The target for a Python compilation is the Python virtual machine, so
on any physical machine, a given version of CPython should generate the
same bytecode. If it doesn't, it's a bug. :-)

> also aren't .pyc files platform dependant?

No--they're platform independent, because they are comprised of opcodes
for the Python virtual machine. They are definitely
implementation-dependent (CPython only) and version-dependent (.pycs
compiled with one version of CPython will not work with another
version), though,

--
Tim Lesher
tle...@gmail.com

Jorge Vargas

unread,
Apr 1, 2006, 5:00:17 PM4/1/06
to turbo...@googlegroups.com
On 3/30/06, Tim Lesher <tle...@gmail.com> wrote:

> yes but i think that will optimice for your machine.

The target for a Python compilation is the Python virtual machine, so
on any physical machine, a given version of CPython should generate the
same bytecode.  If it doesn't, it's a bug. :-)

ok good to know

> also aren't .pyc files platform dependant?

No--they're platform independent, because they are comprised of opcodes
for the Python virtual machine.  They are definitely
implementation-dependent (CPython only) and version-dependent (.pycs
compiled with one version of CPython will not work with another
version), though,

so they do depend on your instalation, not OS but your compiler.

--
Tim Lesher
tle...@gmail.com





Tim Lesher

unread,
Apr 2, 2006, 9:57:27 PM4/2/06
to turbo...@googlegroups.com
On 4/1/06, Jorge Vargas <jorge....@gmail.com> wrote:
> > No--they're platform independent, because they are comprised of opcodes
> > for the Python virtual machine. They are definitely
> > implementation-dependent (CPython only) and version-dependent (.pycs
> > compiled with one version of CPython will not work with another
> > version), though,
>
>
> so they do depend on your instalation, not OS but your compiler.

If you mean the Python bytecode compiler, then yes... otherwise, it
shouldn't matter what C compiler you used to compile Python itself--if
it does, then there's a bug in Python (or the C compiler).

Within the same version release of Python, bytecode is bytecode. What
you can't do, for example, is take a Python 2.4 .pyc and expect it to
work correctly under Python 2.2, or vice-versa.

--
Tim Lesher <tle...@gmail.com>

Reply all
Reply to author
Forward
0 new messages