Search code examples
pythonmodulepackaging

Bundling Multiple Python Modules


I have some Python modules, some of them require more than 20 others. My question is, if there a tool is which helps me to bundle some Python modules to one big file.

Here a simple example:

HelloWorld.py:

import MyPrinter

MyPrinter.displayMessage("hello")

MyPrinter.py:

def displayMessage(msg):
    print msg

should be converted to one file, which contains:

def displayMessage(msg):
    print msg

displayMessage("hello")

Ok, I know that this example is a bit bad, but i hope that someone understand what i mean and can help me. And one note: I talk about huge scripts with very much imports, if they were smaller I could do that by myself.

Thanks.


Solution

  • You cannot and should not 'convert them into one file'.

    If your application consists of several modules, you should just organize it into package.

    There is pretty good tutorial on packages here: http://diveintopython3.org/packaging.html

    And you should read docs on it here: http://docs.python.org/library/distutils.html