views:

266

answers:

2

I'm building a Django app, which I comfortably run (test :)) on a Ubuntu Linux host. I would like to package the app without source code and distribute it to another production machine. Ideally the app could be run by ./runapp command which starts a CherryPy server that runs the python/django code.

I've discovered several ways of doing this:

  1. Distributing the .pyc files only and building and installing all the requirements on target machine.
  2. Using one of the many tools to package Python apps into a distributable package.

I'm really gunning for nr.2 option, I'd like to have my Django app contained, so it's possible to distribute it without needing to install or configure additional things. Searching the interwebs provided me with more questions than answers and a very sour taste that Django packing is an arcane art that everybody knows but nobody speaks about. :)

I've tried Freeze (fails), Cx_freeze (easy install version fails, repository version works, but the app output fails) and red up on dbuilder.py (which is supposed to work but doesn't work really - I guess). If I understand correctly most problems originate form the way that Django imports modules (example) but I have no idea how to solve it.

I'll be more than happy if anyone can provide any pointers or good resources online regarding packing/distributing standalone Django applications.

A: 

The --noreload option will stop Django auto-detecting which modules have changed. I don't know if that will fix it, but it might.

Another option (and it's not ideal) is to obscure some of your core functionality by packaging it as a dll, which your plain text code will call.

wisty
Obscuring my code isn't the goal, but thanks for the idea.The --noreload option doesn't solve any problems (I can't even run the cx_freezed version - see output: http://dpaste.com/129019/)
stricjux
--noreload is only an option for the Django built-in 'runserver' webserver, and wouldn't be applicable to PyCherry, or any other webserver.
Craig Trader
+5  A: 

I suggest you base your distro on setuptools (a tool that enhances the standard Python distro mechanizm distutils).

Using setuptools, you should be able to create a Python egg containing your application. The egg's metadata can contain a list of dependencies that will be automatically installed by easy_install (can include Django + any third-party modules/packages that you use).

setuptools/distutils distros can include scripts that will be installed to /usr/bin, so that's how you can include your runapp script.

If you're not familiar with virtualenv, I suggest you take a look at that as well. It is a way to create isolated Python environments, it will be very useful for testing your distro.

Here's a blog post with some info on virtualenv, as well as a discussion about a couple of other nice to know tools: Tools of the Modern Python Hacker: Virtualenv, Fabric and Pip

codeape