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.

3
  • As a workaround, you can install your own python. Nov 18, 2015 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? Nov 18, 2015 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, 2015 at 14:52

1 Answer 1

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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.