[Tutor] site-packages and permissions to byte-compile

Dave Kuhlman dkuhlman at rexx.com
Tue Jan 30 01:17:53 CET 2007

On Mon, Jan 29, 2007 at 01:35:22PM -0900, Tim Johnson wrote:
> Hello:
> I just installed python 2.5 on Linux/Slackware 10.0
> I have placed three files in the root of site-packages
> on my machine that is 
> /usr/local/lib/python2.5/site-packages
> python appears to be importing this files with no complaint, but
> they are not being byte-compiled. 
> Note: I see that MySQLdb files are being byte-compiled.
> Their ownership is root:root and permissions are 644
> I've set the same ownership and permissions for the other
> files to same.
> What do I need to do to insure that they are byte-compiled?

They do not compile because you are importing these files as a user
that does not have permission to write in the directory containing
those modules.

Your Python distribution should have a Python script called
compileall.py.  You can run that as root to compile *all* the files
in a directory.

For individual files, there is a module named py_compile.py.  Here
is an example of its use on my machine:

    $ python /usr/local/lib/python2.5/py_compile.py test_path.py

Again, you will need write privileges to the directory containing
the module to be compiled (in this case test_path.py).

See the modules py_compile and compileall in the Python standard

You may notice that when you install Python packages (e.g. using
setup.py), compiling happens automatically for you.

Another alternative is to put those modules in a directory in which
you *do* have write access and then add that directory to your


Dave Kuhlman

More information about the Tutor mailing list