4

On a given embedded Linux machine I have a Python 3.3 distribution installed which seems to have the optimization option -O enabled by default. This has the following effects:

  • .pyo files are being generated (rather than .pyc)
  • assert statements have no effect
  • __debug__ is set to False
  • Some IDEs seem to be unable to provide remote debugging (see WingIDE)

Is there a way to disable basic optimization on the command line? I tried to set PYTHONOPTIMIZE to empty string but this does not have any effect.

vaultah
  • 44,105
  • 12
  • 114
  • 143
frans
  • 8,868
  • 11
  • 58
  • 132
  • As a workaround, you can install your own python. – Karoly Horvath Nov 18 '15 at 13:35
  • That's weird, because I could not find such an option in configure script for Python 3.3. Did you carefully inspect environment with `env` or `printenv`, and did you ensure that you are not using a wrapper that forces -O option? – Serge Ballesta Nov 18 '15 at 14:19
  • I just found a patch which is being applied to the Python3.3.3 source in order to activate optimization by default. The distribution is based on Yocto and it comes with that patch. – frans Nov 18 '15 at 14:52

1 Answers1

4

The Python distribution I was using comes with Yocto and basic optimization is activated there by default (Py_OptimizeFlag is hard coded to 1 rather than 0).

That version of Python also comes with an extra -N flag (which is not documented in the usual Python distributions).

So the answer to my question is to either set the -N command line option or to apply a patch to the Python sources which come with Yocto and recompile (as suggested by Karoly Horvath).

frans
  • 8,868
  • 11
  • 58
  • 132