07 August 2010

What is .pyc file

They are 'compiled python files' or 'byte-compiled' version of a module.

So when does it get created:

"When a module is imported for the first time (or when the source is more recent than the current compiled file) a .pyc file containing the compiled code should be created in the same directory as the .py file.

One reason that a .pyc file may not be created is permissions problems with the directory. This can happen, for example, if you develop as one user but run as another, such as if you are testing with a web server. Creation of a .pyc file is automatic if you're importing a module and Python has the ability (permissions, free space, etc...) to write the compiled module back to the directory."

In short, a .pyc is created automatically by python (if it has the permission to do it) when you import the corresponding module (.py file).

No comments: