4

Autotools insists on generating pyo and pyc files when building my project (not when running it) no matter what I do. The problem is that my Python configuration is somewhat strange, and I don't want the Python compiler to run during installation. Is there any way to disable generating these files?

For reference, here are the things I've tried:

  • Setting py_compile=echo so that automake won't compile Python scripts
  • Manually defining install-pythonPYTHON in Makefile.am
  • Setting PYTHONFLAGS=-B
  • Setting PYTHONDONTWRITEBYTECODE in Makefile.am, configure.ac, etc.
  • Creating a new automake variable "python2dir" and installing the script using dist_python2_DATA = Script.py

Basically, if a file ends with the .py extension, Automake WILL create pyc and pyo files, no matter what you do.

Matt Fichman
  • 5,458
  • 4
  • 39
  • 59

2 Answers2

2

See the -B option in the documentation.

martineau
  • 119,623
  • 25
  • 170
  • 301
  • I need a way to tell automake to use that option when installing Python scripts to site-packages. – Matt Fichman Jun 07 '12 at 15:03
  • 2
    Try setting the **PYTHONDONTWRITEBYTECODE** enviroment variable, which is documented [here](http://docs.python.org/using/cmdline.html#environment-variables). – martineau Jun 07 '12 at 15:09
  • I tried putting this in configure.ac, Makefile.am, etc. Didn't work, probably b/c automake has its own environment variables. This is really an automake/autools problem rather than a Python problem. Thanks for the help anyway. – Matt Fichman Jun 07 '12 at 15:22
  • @MattFichman: As I understand your problem, autotools generate byte code files *when building your project*. They will probably be using the `compileall` module, so the command line option and environment variable given in this answer are useless to you – they prevent the automatic creation of pyc/pyo files upon *module import*. You might want to clarify your question. – Sven Marnach Jun 07 '12 at 15:27
  • The automake documentation says "any files listed in noinst_PYTHON will not be compiled" [here](http://www.gnu.org/software/automake/manual/automake.html#Python), so maybe you could put *.py in it. – martineau Jun 07 '12 at 15:44
  • @martineau: Doing this would also mean that no Python file at all is installed when doing `make install`, which seems hardly useful. – Sven Marnach Jun 07 '12 at 16:09
  • @Sven Marnach: It only says they won't be _compiled_. – martineau Jun 07 '12 at 16:42
  • From the [documentation](http://www.gnu.org/software/automake/manual/automake.html): The special prefix `noinst_` indicates that the objects in question should be built but not installed at all. – Sven Marnach Jun 07 '12 at 17:03
2

Please try again with your last attempt.

dist_python_DATA = foo.py

will treat foo.py as any regular file, distribute it, and install it in $(pythondir). _DATA does not trigger any kind of compilation.

adl
  • 15,627
  • 6
  • 51
  • 65