[Tutor] converting a source package into a dll/shared library?

Kent Johnson kent37 at tds.net
Tue Aug 14 16:51:11 CEST 2007


Duncan Gibson wrote:
> Is it possible to convert a Python package, with __init__.py and
> related python modules, into a single DLL or shared library that can
> be imported in the same way?

> We have used py2exe and cx_freeze to create a complete executable,
> but we are curious whether there is a middle way between this single
> executable and distributing all of the source files.

You can get a modest degree of obscurity by distributing the .pyc 
bytecode files instead of the .py source. These can still be decompiled 
and reverse engineered but it is more effort.

I suppose you could rewrite some or all of the code into the Python 
dialect supported by Pyrex and compile it that way.

Pyrex is "a language specially designed for writing Python extension 
modules." The docs say "Almost any piece of Python code is also valid 
Pyrex code." So it might not be too hard to compile your Python source 
into an extension module using Pyrex.
http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/

Kent


More information about the Tutor mailing list