Pyhton Interpreter Startup time
Christopher T King
squirrel at WPI.EDU
Thu Aug 12 17:24:09 CEST 2004
On Thu, 12 Aug 2004, Neil Benn wrote:
> Is there a way to have a 'stripped' down Python interpreter which can
> start up very quickly on a windows box.
Two things you can do are:
1) Run Python as "python -S". Normally, Python does an 'import site'
before running other code. Starting with 2.3, this does lots of expensive
localization goo, etc.; my guess is your script doesn't need it to execute
correctly, if it doesn't use any i18n functions.
2) Pre-compile the script. Normally, Python generates .pyc files for
imported modules so it doesn't have to re-parse the source code, but it
won't do this for a script specified on the command line. You can force
it to compile your script by importing the script in the interactive
interpreter, but this will also run your script (possibly not desirable).
You can compile the script without running it by using the py_compile
python -c 'import py_compile; py_compile.compile("my_script.py")'
You can then run the compiled version using 'python my_script.pyc'
('python my_script.py' will ignore the compiled version).
> Once thing I was thinking of was to use PyExe to make a
> quick startup (does it compile down to C code, therefore not using the
> Python interpreter at runtime?). Is this a possible solution?
Nope. py2exe just embeds the Python interpreter in the .exe. If
anything, startup would be slower, since py2exe also places all required
modules in a ZIP archive.
More information about the Python-list