Produce .pyc without execution

François Pinard pinard at
Mon Nov 1 11:44:44 EST 1999

"Adrian Eyre" <a.eyre at> writes:

> > However, I could not decently propose this scheme for integration in
> > Automake, and that makes it a bit unsatisfactory.  It would be nicer,
> > for example, if `src/*.py' files were recompiled into the `src/' build
> > hierarchy from the `src/' distribution hierarchy, and then installed from
> > there.  But `compileall' wants to install compiled files next to sources
> > in the same directory, which is a bit inconvenient.  Any simple solution?

> This is the default behaviour for Python, and without modifying its source
> the .pyc will always be created in the same dir as the source. Can't
> you add something like:

> install-data-hook:
> 	@echo 'import compileall; compileall.compile_dir("$(pkgdatadir)")' \
> 	| $(PYTHON); \
> 	for pyc in $(pkgdatadir)/*.pyc; do mv $$pyc somewhere_else/; done

Not really.  There are many things to keep in mind for fitting well in
the Automake spirit, and these two are a bit more relevant, here:

* The distribution hierarchy (by opposition to build hierarchy) should be
  considered read-only, as if, say, it was already exploded in a CD-ROM; a
  mere, simple installation should not modify, create or delete files in it;
  this is only allowed in the build hierarchy.

* Many people do `make all' as one user, and `make install' as a different
  user (`root' or `bin', say), so ideally, all needed files should be
  prepared in the build hierarchy at `make all' time, `make install'
  should not create any more files in the build directory, once `make all'
  has been done.  The only files `make install' may create sit in the various
  installation directories.

Above, $(pkgdatadir) is an installation directory, so things are already in
their final place, no need to move them further once there.  The scheme I
used is acceptable when one wants to provide all sources installed with the
compiled forms, but some people prefer to keep sources non-installed, just
to spare disk space, say.  What would be ideal is a way for `compile_dir'
to produce `.pyc' in the build hierarchy directly from the source hierarchy
at `make all' time, and that `make install' just move these ready `.pyc'
files into the installation directories.

François Pinard

More information about the Python-list mailing list