Question

I have written a simple web application with embedded web server (tornado), database (sqlalchemy using sqlite for now), and the whole shabang. I would like to bundle it all up into a single self-contained directory with a single exe that can be run. The deployment scenario absolutely demands a one click install and run like this.

I have absolutely failed trying to get py2exe or pyinstaller to bundle up my code. The problem has directly to do with the directory structure and layout, which is as follows. I do not want to change the directory layout to much. Can someone suggest how I can get this with either py2exe or pyinstaller or any other suitable tool?

project/
|-> main.py

|-> libs/
    |-> tornado/ (The full git rep as a submodule)
        |-> tornado/ (The actual package)
    |-> sqlalchemy/

|-> src/
    |-> support-1.py
    |-> support-2.py

|-> static/
    -> js/
    -> img/
    -> css/

|-> templates/
Was it helpful?

Solution

Well, sorry to answer my own question. But much googling and trial and error, I managed to get this working. I am pasting my setup.py (for py2exe) below for anyone who has similar issues getting tornado + sqlalchemy + sqlite working with py2exe. When I run python setup.py py2exe, the last lines mention that some module are missing. But this had no impact on the execution of the program.

> "['Carbon', 'Carbon.Files', '_curses', '_scproxy', 'django.utils',
> 'dummy.Process', 'pkg_resources', 'pysqlite2', 'simplejson',
> 'sqlalchemy.cprocessors', 'sqlalchemy.cresultproxy', 'tornado.epoll']"

Here is my setup.py:

import glob, os, sys

curr_dir = os.path.abspath('.')
pare_dir = os.path.abspath('..')

sys.path = [os.path.join(pare_dir, 'py2exe-0.6.9', 'py2exe'),
           os.path.join(curr_dir, 'src'),
           os.path.join(curr_dir, 'libs', 'tornado'),
           os.path.join(curr_dir, 'libs', 'sqlalchemy'),
           os.path.join(curr_dir, 'libs')] + sys.path


from distutils.core import setup
import py2exe

data_files = [('', ['config.json']),
              ('db', ['db/prs.db']),
              ('templates',      glob.glob('templates/*.*')),
              ('static',         glob.glob('static/*.*  ')),
              ('static/css',     glob.glob('static/css/*.*')),
              ('static/js',      glob.glob('static/js/*.*')),
              ('static/js/libs', glob.glob('static/js/libs/*.*')),
              ('static/img',     glob.glob('static/img/*.*')),
              ]

setup(console=['prs.py'], options={
    'py2exe' : {
        'includes' : ['demjson'],
        'packages' : ['sqlalchemy.dialects.sqlite'],
        }},
    data_files=data_files,
    )
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top