Build an executable from a Python application using Django
From the revision [717], you can build an executable from a project using Django. PyInstaller will take care of a lot of magic needed to correctly build Django applications. For instance, it will parse all your files and find all the dotted-names strings that refers to module names (eg: within settings.py) and make sure that all those modules are packaged.
But alas there is still a manual step that it is required: you cannot run PyInstaller over the manage.py script directly, but you will have to create a bootstrap script that imports manage.py. This bootstrap script must reside in a directory which is not the one with the manage.py script itself (for instance, its parent directory).
The following example should clarify the required steps.
Example
Let's say that your Django project is called foobar. If you used the django-admin.py wizard, you probably have ended up with a directory structure like this:
foobar/
__init__.py
manage.py
settings.py
urls.py
What you want to do is to create a bootstrap script, with the following contents:
import foobar.manage foobar.manage.run_server()
and place it in the parent directory:
bootstrap.py
foobar/
__init__.py
manage.py
settings.py
urls.py
Now you can use PyInstaller as usual:
$ python Makespec.py --console --name=foobar bootstrap.py $ python Build.py foobar.spec
Notice that I'm using the --name option when invoking Makespec.py to make sure I end up with a packaged executable called foobar (and not bootstrap).
If you prefer, you can put your bootstrap script in any other place, but you will have to add the parent directory to either PYTHONPATH or the pathex list within the spec file, so that the import works correctly.
NOTE: It's important that the import line uses appname.manage. You cannot use import manage directly.
What if it does not work?
Django uses a lot of magic behind the hood, so some quirks are expected. If the application does not run, you should see the traceback in the console. If it is an ImportError, it is probably a missing module whose dependency PyInstaller was not able to automatically discover.
The quickest workaround is to explicitly import that module somewhere, for instance in the bootstrap script. But please report the incident to the mailing list so that we can prepare a proper fix that everyone can benefit from.
