How to force creation of a .pyc?

Peter Hansen peter at engcorp.com
Thu Feb 23 09:07:20 EST 2006


mrstephengross wrote:
> I would like to distribute a python program, but only in .pyc form (so
> that people cannot simply look at my code). Is there a way to do this?
> I've read up a little on the logic by which python creates .pyc's, and
> it sounds like python requires the main executed program to be in .py
> format. Any ideas?

Use the compileall module (e.g. function compile_dir) and run the .pyc 
file(s) directly.  Python doesn't care if the main one is in .py format 
and will happily run a .pyc if there's no matching .py file around.

-Peter




More information about the Python-list mailing list