2

How can I include pdftk and gsprint with a distributable Python program?

I've written a short Python module that takes several source PDFs, rearranges pages, and then prints them into correctly-ordered, helpfully-stapled packets (I'd be grateful for any feedback on the module over on GitHub, too). This makes it a lot easier to print large numbers of these packets at once. I use pdftk and gsprint (via subprocess.call) to wrangle and print the PDFs.

Now, I'd like to be able to distribute this to my colleagues at other study sites around the country. I'm making three assumptions about them:

  1. They are much less technically inclined than I am, so getting pdftk and gsprint installed and onto their system paths will probably be tough (assuming their local IT even permits such a thing);
  2. They are almost all using Windows.
  3. Users won't have Python installed (in reality some will, but who knows)

My ideal would be a single executable file that somehow has a Python interpreter, my module, pdftk, Ghostscript, and gsprint rolled up inside. Is that feasible, and if so, how? I've seen some tutorials on working with C and Java libraries, but it seems like I just don't have the vocabulary and conceptual knowledge to sort this out.

Matt Parker
  • 26,709
  • 7
  • 54
  • 72

2 Answers2

2

To create a single standalone executable you can use pyinstaller ...totally self-contained, which runs without any external dependency.

  • I'm not sure that will let me package non-Python libraries, though - all the examples cited are either Python modules or C libraries used through `ctypes`. Sorry if I'm missing something obvious... – Matt Parker Dec 26 '12 at 23:37
  • Thanks. Here's a [Google Group question](https://groups.google.com/forum/#!msg/PyInstaller/yDwJ0LxWztk/giCEW8mfgLUJ) that addresses my specific case in more detail; I'll give that a try, but it looks this should work. Thanks. – Matt Parker Jan 03 '13 at 18:04
0

You need to freeze your Python project, using a freezer for the purpose:

The task is usually as simple as executing a simple command, like cxfreeze main.py --target-dir dist or creating a setup.py file, where specific methods of the freezer are invoked. In most of the cases it would automatically figure the dependencies, but check the documentation.

Jordan Jambazov
  • 3,460
  • 1
  • 19
  • 40