I've been playing with pyglet. It's very nice. However, if I run my code, which is in an executable file (call it game.py) prefixed with the usual
#!/usr/bin/env python
by doing
./game.py
then it's a bit clunky. But if I run it with
python -O ./game.py
or
PYTHONOPTIMIZE=1 ./game.py
then its super-smooth.
I'm don't care much why it runs slow without optimization; pyglet's documentation mentions that optimizing disables numerous asserts and also OpenGL's error checking, and I'm happy to leave it at that.
My question is: how do people distributing Python code make sure the end users (with zero interest in debugging or modifying the code) run the optimized version of the code. Surely there's some better way than just telling people to make sure they use optimization in the release notes (which they probably won't read anyway) ?
On Linux I can easily provide a ./game
script to run the file for end users:
#!/bin/sh
PYTHONOPTIMIZE=1 ./game.py $*
but that's not very cross-platform.
I have an idea I ought to be able to change the #!
line to
#!/usr/bin/env PYTHONOPTIMIZE=1 python
or
#!/usr/bin/env python -O
but those don't seem to work as expected, and I'm not sure what they'd do on Windows.
Is there some way of controlling optimization from within the code I'm unaware of ? Something like:
import runtime
runtime.optimize(True)
What's considered best-practice in this area by people shipping multi-platform python code ?