Distribute Django program to run on a local computer

46 views
Skip to first unread message

Rob Hudson

unread,
Jul 31, 2006, 11:50:55 AM7/31/06
to Django users
Quick version:
Is there a way to bundle up a Django application, maybe wrap an
installer around it if need be, and distribute it by CD to install and
run on a person's local system. Preferrably cross platform (Windows
and Mac).

Long version that helps explain why we need this:
I work for a company that builds web based health education programs.
Most of our funding comes from grants. As part of the grant review
process, the reviewers must remain anonymous and therefore, we cannot
simply send a URL to our prototype. We've decided in the past to
distribute a "microserver" called Microweb, that can run PHP programs
from CD. But it's Windows only, and PHP or Perl only.

We're currently in the process of evaluating other frameworks as we
migrate away from our in-house CMS to something more flexible. I'm a
big fan of Django and have used it on a couple personal side projects
so I'd love to see if Django can work for us. Plus, the scientists
would love the admin and we'd love how quickly we could set it up for
them.

I'm thinking SQLite would be the backend database since it's
lightweight and cross platform. I know Django itself will run on
Windows, Linux, and Mac. But the challenge is distributing it for an
easy, self contained install (no internet connection).

Would something like py2app work for this?

If anyone has experience with this, I'd very much appreciate some
guidance. Also, if others are interested in the outcome, I can report
on whatever progress I make on this front.

Thanks,
Rob

indir...@gmail.com

unread,
Jul 31, 2006, 12:58:54 PM7/31/06
to Django users
Don't have any experience with this. Some options I've come across,
that may or may not work:

1) http://www.py2exe.org/ - Never used it, but have it bookmarked for
when I do need it. Like py2app but creates exe
2) http://www.voidspace.org.uk/python/programs.shtml#movpy -- From the
website: "Movable Python is a distribution of Python (for Windows) that
doesn't need to be installed. It easily fits onto a USB memory stick"
3) http://peak.telecommunity.com/DevCenter/setuptools -- No experience
creating packages with it, but used it lots of times to install

Chris

Joseph Heck

unread,
Jul 31, 2006, 2:27:10 PM7/31/06
to django...@googlegroups.com
It's a little more tricky than just packaging Django up nicely because of the external dependencies. I have a set of windows installers that I have bundled up for myself to drop onto windows machines to get them set up with a dev environment (sqlite3 based). It's a little tricker on the Mac - but only because getting all the pieces parts installed is sort of a pain (no binary installer and I haven't gone to the trouble to make one myself).

For any given platform you could make up a package and drop it around i'd expect. But it is a fair bit of work getting everything together.

-joe

Facundo Casco

unread,
Jul 31, 2006, 7:07:46 PM7/31/06
to django...@googlegroups.com
maybe this make no sense to you but what about making a custom Linux
liveCD with everything you need installed. All the end-user has to do is
know how to boot from CD, no install, nothing left on their systems.

Facundo

Joseph Heck wrote:
> It's a little more tricky than just packaging Django up nicely because
> of the external dependencies. I have a set of windows installers that
> I have bundled up for myself to drop onto windows machines to get them
> set up with a dev environment (sqlite3 based). It's a little tricker
> on the Mac - but only because getting all the pieces parts installed
> is sort of a pain (no binary installer and I haven't gone to the
> trouble to make one myself).
>
> For any given platform you could make up a package and drop it around
> i'd expect. But it is a fair bit of work getting everything together.
>
> -joe
>

> On 7/31/06, * Rob Hudson* <trebor...@gmail.com

--
AMV Multiviajes Argentina
Esmeralda 847 Piso 12 Of. 'G'
C1007ABI - Buenos Aires
Argentina
Tel: +54 11 5031-3060 / 3061
Fax: +54 11 4313-6141

facundo.vcf

Joseph Heck

unread,
Jul 31, 2006, 7:52:37 PM7/31/06
to django...@googlegroups.com
I've been doing exactly that myself - I have a VMWare image (not exactly LiveCD, but VMWare player is free...) that I use for a development environment. At OSCON I was taking briefly about it. I need to clean it up and post it. Right now it's sort of beleagured with all my additional stuff.

-joe

Malcolm Tredinnick

unread,
Jul 31, 2006, 8:22:10 PM7/31/06
to django...@googlegroups.com
On Mon, 2006-07-31 at 16:52 -0700, Joseph Heck wrote:
> I've been doing exactly that myself - I have a VMWare image (not
> exactly LiveCD, but VMWare player is free...) that I use for a
> development environment. At OSCON I was taking briefly about it. I
> need to clean it up and post it. Right now it's sort of beleagured
> with all my additional stuff.

The original poster required running on Mac as well, though. That rules
out VMWare (Mac on Intel isn't nearly widely enough deployed yet to be a
reasonable assumption, even if VMWare supports it).

Live CDs have a slight drawback in that they take over your computer
whilst you are using them, so evaluating a submission whilst taking
notes requires two computers and you lose the ability to cut and paste
and easily take screenshots, etc, without a lot of fiddling around
running a remote viewer.

So we still have a bit of thinking to do to reach nirvana here.

Malcolm


Rob Hudson

unread,
Jul 31, 2006, 11:55:18 PM7/31/06
to Django users
Malcolm Tredinnick wrote:
> Live CDs have a slight drawback in that they take over your computer
> whilst you are using them, so evaluating a submission whilst taking
> notes requires two computers and you lose the ability to cut and paste
> and easily take screenshots, etc, without a lot of fiddling around
> running a remote viewer.

Yes, ideally it would launch Django using the built-in WSGI web server,
use SQLite, and "just work". I'm sure there'd have to be some sort of
wrapper script to set up the environment, launch the server, and open a
brower to localhost to get the feel of a single executable.

I appreciate the feedback so far.

As an aside: We're also investigating Rails and I discovered this link
on distributing Rails which looks promising. My next step will be to
see if there are Python equivalents and see if that provides me any
leads:
http://www.erikveen.dds.nl/distributingrubyapplications/rails.html

Thanks again,
Rob

Frank Stüss

unread,
Aug 1, 2006, 1:55:25 AM8/1/06
to django...@googlegroups.com
Maybe i misunderstood but what about <http://www.colinux.org> then?

You run a linux web server with django and could start it from theoretically
every platform linux runs on. In parallel to the host system, not as 'live'
system. You can access it via the host systems browser, so this should be
possible.

Listening to Nirvana, i am thinking about a local web app for my customers
running on django (a catalogue system) and therefore i should have the same
problem.

Frank

Julio Nobrega

unread,
Aug 1, 2006, 8:04:30 PM8/1/06
to django...@googlegroups.com
I was going to recommend a Live CD too, but let me get back a little
to the first thread email and perhaps say something really stupid:

On 7/31/06, Rob Hudson <trebor...@gmail.com> wrote:

> As part of the grant review
> process, the reviewers must remain anonymous and therefore, we cannot
> simply send a URL to our prototype

Can't you use SSL, and tell the reviewers to use an anonymizer proxy?

This is so much easier than hacking a Knoppix CD (been there, done that...)

--
Julio Nobrega - http://www.inerciasensorial.com.br

Rob Hudson

unread,
Aug 2, 2006, 1:43:25 AM8/2/06
to Django users
Julio Nobrega wrote:
> Can't you use SSL, and tell the reviewers to use an anonymizer proxy?

Not really. We have to assume no internet connection at all and ship a
self-contained program. It makes things difficult and adds extra work.
With a PHP solution we were able to use Microweb (indigostar.com) and
that worked well enough.

Today I downloaded the 0.95 release, started a project and app, and
modified the manage.py with the following lines and was able to run the
project without a globally installed Django:

import sys
sys.path.append("/path/to/django")

I ran out of time to go much further today, but my hope is that with
the above and py2exe or py2app, I can distribute Django and my project
as an executable. There's still lots to figure out and test but that's
where I'm heading.

-Rob

Rob Hudson

unread,
Aug 2, 2006, 12:32:25 PM8/2/06
to Django users
I've made a little more progress this morning...

I created a run script to start up Django without needed to edit
manage.py directly. With this run script I can add other features
later. Here's the gist of it. (Quotes is my test app I created)

#!/usr/bin/env python
import sys, os
sys.path.append(os.getcwd())

from Quotes.manage import *
# We can also pass in host:port info to start server on.
# Possibly add checks to see if port is open already and increment
# to next one for the case of >1 app running simultaneously.
execute_manager(settings, ['','runserver'])

# NOTE: execute_manager takes over script control. If we want to
# fire up a browser window we need to do that in another thread.
# Now that server is running, open web browser?
#import webbrowser
#webbrowser.open_new('http://localhost:8000')

Some other notes: My directory structure is:
Django-0.95/
(all of the source of Django)
Quotes/ (my app)
run.py
py2app-setup.py

My py2app-setup.py file is simply this:
#!/usr/bin/env python
from distutils.core import setup
import py2app

setup(
app=['run.py'],
)

Running this command to build py2app and include a few modules that it
told me it was missing:

python py2app-setup.py py2app
--includes=django.contrib.auth,django.contrib.sessions,django.contrib.sites

Executing the resulting "run.app" from the dist directory gives me the
following error:

Validating models...
Unhandled exception in thread started by <function inner_run at
0x27a9f0>
Traceback (most recent call last):
File "django/core/management.pyc", line 1039, in inner_run
File "django/core/management.pyc", line 1003, in validate
File "django/core/management.pyc", line 815, in get_validation_errors
File "django/db/__init__.pyc", line 18, in ?
OSError: [Errno 20] Not a directory:
'/Users/rhudson/Desktop/Django-0.95/dist/run.app/Contents/Resources/lib/python2.3/site-packages.zip/django/db/backends'

It looks like it started fine (the validating models...), but then got
caught up in the database stuff. I'll take a deeper look but that's
about all the time I can spend on this today.

Rob Hudson

unread,
Aug 3, 2006, 4:25:09 PM8/3/06
to Django users
If anyone is still following along I got past the last error by
specifically adding "django.db.backends.sqlite3.base" to my list of
includes. This got me a little further. The server will successfully
start up and I can make a request. I got a traceback in the browser
about django.middleware.common not existing so I added that to the
include line. The next one was django.contrib.sessions.middleware, so
I added that too. Here's the current list of includes:

python py2app-setup.py py2app
--includes=django.contrib.auth,django.contrib.sessions,django.contrib.sites,django.contrib.admin,Quotes.quotes,django.db.backends.sqlite3.base,django.middleware.common,django.contrib.sessions.middleware

Currently in the browser I get the following error:

Traceback (most recent call last):

File "django/core/servers/basehttp.pyc", line 272, in run

File "django/core/servers/basehttp.pyc", line 615, in __call__

File "django/core/handlers/wsgi.pyc", line 143, in __call__

File "django/core/handlers/base.pyc", line 31, in load_middleware

ImproperlyConfigured: Error importing middleware
django.contrib.sessions.middleware: "cannot import name backend"

The interesting thing is... if I refresh the browser page it get's
beyond this point and continues to report missing modules. I've
continued to add them as it finds them missing and am not up to this
point in my py2app build command:

python py2app-setup.py py2app
--includes=django.contrib.auth,django.contrib.sessions,django.contrib.sites,django.contrib.admin,Quotes.quotes,django.db.backends.sqlite3.base,django.middleware.common,django.contrib.sessions.middleware,django.template.defaulttags,django.template.defaultfilters,Quotes.settings,Quotes.urls,Quotes.quotes.models,Quotes.quotes.views,django.template.loader_tags,django.db.models.base

At this point, I get a ViewDoesNotExist error in the browser:

Traceback (most recent call last):

File "<unknown>" in ?

ViewDoesNotExist at /quote/
Tried index in module Quotes.quotes.views. Error was: 'module' object
has no attribute 'Model'

I do have an index method in my view. The page works when I simply run
"python manage.py runserver", in other words, it works when not
packinging it via py2app.

I think this is as far as I'll get today.

Malcolm Tredinnick

unread,
Aug 3, 2006, 8:28:10 PM8/3/06
to django...@googlegroups.com
On Thu, 2006-08-03 at 13:25 -0700, Rob Hudson wrote:
> If anyone is still following along

I am. Not a Mac or Windows user, but you're solving an interesting
problem. The end result is going to be useful. Thanks for sharing this
information.

> I got past the last error by
> specifically adding "django.db.backends.sqlite3.base" to my list of
> includes. This got me a little further. The server will successfully
> start up and I can make a request. I got a traceback in the browser
> about django.middleware.common not existing so I added that to the
> include line. The next one was django.contrib.sessions.middleware, so
> I added that too. Here's the current list of includes:

That's going to get tiring quickly. Is there some way to pass this as a
Python list or something to py2app? Ideally, you would like to include
every directory under django/. The problem is that importing some of
this stuff requires a functioning settings file.

Have you had to set DJANGO_SETTINGS_MODULE somewhere in order to get
this all to work?

> python py2app-setup.py py2app
> --includes=django.contrib.auth,django.contrib.sessions,django.contrib.sites,django.contrib.admin,Quotes.quotes,django.db.backends.sqlite3.base,django.middleware.common,django.contrib.sessions.middleware
>
> Currently in the browser I get the following error:
>
> Traceback (most recent call last):
>
> File "django/core/servers/basehttp.pyc", line 272, in run
>
> File "django/core/servers/basehttp.pyc", line 615, in __call__
>
> File "django/core/handlers/wsgi.pyc", line 143, in __call__
>
> File "django/core/handlers/base.pyc", line 31, in load_middleware
>
> ImproperlyConfigured: Error importing middleware
> django.contrib.sessions.middleware: "cannot import name backend"

Not sure if it will help you, but what it is really saying is "cannot
import <whatever the name of your database is> backend".

This is probably the silliest error message in Django. Unfortunately the
informative bit gets lost whilst moving up the stack to where we report
the error. I seem to remember it's not entirely trivial to fix, but it's
pretty embarrassing so we'll get to it one day.

So you have a real error here: something about the database layer not
being loadable.

[...]


>
> I think this is as far as I'll get today.

I can only say "don't give up" here. Because of the way Django works
under the covers, with dynamic imports and the like, it is not entirely
trivial to work out what is going on: either for you or py2app, I
suspect.

So please feel free to ask as many questions as you need to. I can
understand that the learning curve here is a bit steep and this probably
isn't the part of your submission you want to spend days on. Like I say,
this is an interesting problem and worth solving, so we'll help you as
much as we can.

Cheers,
Malcolm

Rob Hudson

unread,
Aug 3, 2006, 11:37:59 PM8/3/06
to Django users
Malcolm Tredinnick wrote:
> On Thu, 2006-08-03 at 13:25 -0700, Rob Hudson wrote:
> > If anyone is still following along
>
> I am. Not a Mac or Windows user, but you're solving an interesting
> problem. The end result is going to be useful. Thanks for sharing this
> information.

Thanks for the support. I posted to the py2app (actually, the
Pythonmac-SIG) mailing list and got a somewhat discouraging reply from
Bob Ippolito...
http://mail.python.org/pipermail/pythonmac-sig/2006-August/017988.html

I suppose I should be hunting down the --packages path. I'm not sure
what he means by "in-package data files" but I'll post a follow up over
there.

-Rob

Rob Hudson

unread,
Aug 4, 2006, 3:01:29 PM8/4/06
to Django users
A little more info this morning...

Bob Ippolito posted a followup with some guidance. It makes it much
simpler but I'm still seeing the same errors. Here's the latest
py2app-setup.py:

#!/usr/bin/env python
from setuptools import setup
setup(
app=["run.py"],
setup_requires=["py2app"],
options=dict(py2app=dict(packages=["django","Quotes"],)),
)

Now I simply run this from within the Django-0.95 directory:
python py2app-setup.py py2app

And then launch Django:
# /dist/run.app/Contents/MacOS/run
Validating models...
Skipping validation because things aren't configured properly.
Django version 0.95, using settings 'Quotes.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

Everytime the first page hit always produces the following error yet
concurrent page requests do not show this error. This seems very odd
to me and suggests something strange is happening...

Traceback (most recent call last):
File "django/core/servers/basehttp.pyc", line 272, in run
File "django/core/servers/basehttp.pyc", line 615, in __call__
File "django/core/handlers/wsgi.pyc", line 143, in __call__
File "django/core/handlers/base.pyc", line 31, in load_middleware
ImproperlyConfigured: Error importing middleware
django.contrib.sessions.middleware: "cannot import name backend"

[04/Aug/2006 13:49:45] "GET / HTTP/1.1" 500 409

Requesting "/" gives me an approriate error since I don't have the
urls.py configured to do anything for this:
[04/Aug/2006 13:49:50] "GET / HTTP/1.1" 404 1952

In the HTML it shows this:

Using the URLconf defined in Quotes.urls, Django tried these URL
patterns, in this order:

1. ^quote/$
2. ^admin/

The current URL, /, didn't match any of these.

If I try to hit my "/quote/" page I get a 500 error at the terminal:
[04/Aug/2006 13:52:50] "GET /quote/ HTTP/1.1" 500 25750
this error in the browser:


ViewDoesNotExist at /quote/
Tried index in module Quotes.quotes.views. Error was: 'module' object
has no attribute 'Model'

Request Method: GET
Request URL: http://localhost:8000/quote/
Exception Type: ViewDoesNotExist
Exception Value: Tried index in module Quotes.quotes.views. Error was:


'module' object has no attribute 'Model'

Exception Location: <unknown> in ?, line ?

I do have an index method in my quotes/views.py and the error message
is a bit confusing to me.

Trying "/admin/" I get another 500 error and the following:
ImportError at /admin/
No module named urls
Request Method: GET
Request URL: http://localhost:8000/admin/
Exception Type: ImportError
Exception Value: No module named urls
Exception Location: <unknown> in ?, line ?

Looking at the py2app output I can verify that
django.contrib.admin.urls is being pulled in.

I'm curious if one of the Django developers could test this and
possibly look at some of the error messages and the code to see if
there are ways to do the same thing that is compatible with py2app? Is
that even a sane approach? Or if there are recommendations for next
steps I'd appreciate it.

I'm feeling like this is close. Django successfully reports a 404.
But it is having trouble with my app and the admin so some parts seem
to be missing.

I feel I'm stuck on progress on the Mac using py2app. I may switch to
Windows with py2exe and see if that produces the same errors.

Thanks,
Rob

Rob Hudson

unread,
Aug 21, 2006, 8:31:00 PM8/21/06
to Django users
I started the process of testing this on Windows and found that Python
is only about 12MB installed. Compared to about 120MB for Ruby. My
thinking now is that all we need is a local copy of Python, a wrapper
script to get Django up and running and to launch a browser at
localhost:8000, and we're golden.

I've gotten Django to run on Windows with Pysqlite2 and set up a basic
app. My next step is to see if I can build an executable to launch
Django. I've got a run.py script but it launches Python in a command
window. Unless I can answer a couple questions I may make a custom
program to handle this:

1. From within my run.py script can I tell it where the Python
executable is, similar to a Linux machine and its "/usr/bin/python"
script header? I'm looking for a relative path along the lines of
"Python24\python.exe".

2. Can I kick off Django via my run.py script but not have it throw up
a command window? I'm guessing maybe something with Tk/Tkinter but I'd
like to avoid those extra dependencies if I can.

Thanks,
Rob

Alan Green

unread,
Aug 21, 2006, 9:31:28 PM8/21/06
to django...@googlegroups.com
On 8/22/06, Rob Hudson <trebor...@gmail.com> wrote:
>
> I started the process of testing this on Windows and found that Python
> is only about 12MB installed. Compared to about 120MB for Ruby. My
> thinking now is that all we need is a local copy of Python, a wrapper
> script to get Django up and running and to launch a browser at
> localhost:8000, and we're golden.
>
> I've gotten Django to run on Windows with Pysqlite2 and set up a basic
> app. My next step is to see if I can build an executable to launch
> Django. I've got a run.py script but it launches Python in a command
> window. Unless I can answer a couple questions I may make a custom
> program to handle this:
>
> 1. From within my run.py script can I tell it where the Python
> executable is, similar to a Linux machine and its "/usr/bin/python"
> script header? I'm looking for a relative path along the lines of
> "Python24\python.exe".

You want sys.executable:
http://docs.python.org/lib/module-sys.html#l2h-342

Also, did you look at Movable Python? For a few dollars per
installation, it may save you some headaches:
http://www.voidspace.org.uk/python/movpy/

> 2. Can I kick off Django via my run.py script but not have it throw up
> a command window? I'm guessing maybe something with Tk/Tkinter but I'd
> like to avoid those extra dependencies if I can.

pythonw.exe (in your python install directory) is the same as
python.exe, but without the console output.

Alan.


--
Alan Green
al...@bright-green.com - http://bright-green.com

Reply all
Reply to author
Forward
0 new messages