Search code examples
pythonpython-2.7emacsaquamacs

Execute AquaMacs buffer that has "from __future__ import ..."


Running AquaEmacs, I want to execute a buffer (C-c C-c) in Python.

The buffer starts with:

from __future__ import print_function

The execution in AquaEmacs starts with:

import sys,imp
if'test_one_liners' in sys.modules:
   imp.reload(test_one_liners)
else:
   import test_one_liners

where test_one_liners.py is my file. This gives this error:

 SyntaxError: from __future__ imports must occur at the beginning of the file

Anyone know where and how to fix this?

Let me add the information again to make it clear.

Create this buffer:

 from __future__ import print_function

 print("Hello")

Use File/Change Buffer Mode/Python to make it Python and C-c C-c to execute it; it need not be saved. The buffer is written to some temporary file and fails with SyntaxError: from __future__ imports must occur at the beginning of the file. The traceback includes a generated file which contains a reference to a temp file. What should happen instead it printing Hello.


Solution

  • This was a bug in python-mode.el which is fixed in the current release. It looks like aquamacs is bundled with an older version of python-mode.el.

    The bug report is here: bug #1063884 and the fix here.

    You should update your python-mode.el package.