Django to desktop app with pyinstaller
Question: I'm trying to convert a django project into a desktop app. I've downloaded the
developer version of pyinstaller: github/pyinstaller/pyinstaller.

hookutils.py is modified as stated here:
<http://www.pyinstaller.org/ticket/754> in order for pyinstaller to find my
root directory: _Django root directory c:\Workspace\mysite\mysite_

The project I'm trying to compile is the initial project gotten after running:
_django-admin.py startproject mysite_ , so no apps created yet.

When following the steps as described on pyinstaller
(<http://www.pyinstaller.org/wiki/Recipe/DjangoApplication>) I get some errors
when trying to run the server ( .\dist\mysite\mysite.exe runserver
localhost:8080):

    
    
    c:\Workspace\compiled>.\dist\mysite\mysite.exe runserver
    Traceback (most recent call last):
      File "<string>", line 11, in <module>
      File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.core.management", line 453, in execute_from_command_line
      File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.core.management", line 392, in execute
      File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.core.management", line 263, in fetch_command
      File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.core.management", line 109, in get_commands
      File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.conf", line 53, in __getattr__
      File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.conf", line 49, in _setup
      File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.conf", line 71, in _configure_logging
      File "C:\Workspace\pyinstaller-develop\PyInstaller\loader\pyi_importers.py", line 270, in load_module
    exec(bytecode, module.__dict__)
      File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.utils.log", line 6, in <module>
      File "C:\Workspace\pyinstaller-develop\PyInstaller\loader\pyi_importers.py", line 270, in load_module
    exec(bytecode, module.__dict__)
      File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.views.debug", line 11, in <module>
      File "C:\Workspace\pyinstaller-develop\PyInstaller\loader\pyi_importers.py", line 270, in load_module
    exec(bytecode, module.__dict__)
      File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.http", line 1, in <module>
      File "C:\Workspace\pyinstaller-develop\PyInstaller\loader\pyi_importers.py", line 270, in load_module
    exec(bytecode, module.__dict__)
      File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.http.cookie", line 5, in <module>
      File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.utils.six", line 84, in __get__
      File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.utils.six", line 103, in _resolve
      File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.utils.six", line 74, in _import_module
    ImportError: No module named Cookie
    

If I then import Cookie in manage.py then, another error appears:

    
    
    Unhandled exception in thread started by <bound method Command.inner_run of <django.core.management.commands.runserver.Command object at 0x02D86CF0>>
    Traceback (most recent call last):
      File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.core.management.commands.runserver", line 92, in inner_run
      File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.core.management.base", line 280, in validate
      File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.core.management.validation", line 35, in get_validation_errors
      File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.db.models.loading", line 166, in get_app_errors
      File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.db.models.loading", line 75, in _populate
      File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.db.models.loading", line 96, in load_app
      File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.utils.importlib", line 35, in import_module
      File "C:\Workspace\pyinstaller-develop\PyInstaller\loader\pyi_importers.py", line 270, in load_module
    exec(bytecode, module.__dict__)
      File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.contrib.auth.models", line 18, in <module>
      File "C:\Workspace\pyinstaller-develop\PyInstaller\loader\pyi_importers.py", line 270, in load_module
    exec(bytecode, module.__dict__)
      File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.contrib.auth.hashers", line 8, in <module>
      File "C:\Workspace\pyinstaller-develop\PyInstaller\loader\pyi_importers.py", line 270, in load_module
    exec(bytecode, module.__dict__)
      File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.test", line 6, in <module>
      File "C:\Workspace\pyinstaller-develop\PyInstaller\loader\pyi_importers.py", line 270, in load_module
    exec(bytecode, module.__dict__)
      File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.test.testcases", line 35, in <module>
    ImportError: cannot import name _doctest
    

I have tried to import doctest, but it doesn't help.

Using python 2.7.4 and django 1.5.1

**Edit:** So by adding django.test and HTMLParser to the manage.py, I got it
to work:

    
    
    import os
    import sys
    import Cookie
    
    if __name__ == "__main__":
        os.environ.setdefault("DJANGO_SETTINGS_MODULE", "OTA.settings")
    
        from django.core.management import execute_from_command_line
    
        import django.test
        import HTMLParser
        execute_from_command_line(sys.argv)
    


Answer: Django imports local doctest module. Maybe try `import django.test`?

Also from the PyInstaller docs about including additional modules:

>   * You can give additional files on the PyInstaller command line.
>   * You can give additional import paths on the command line.
>   * You can edit the myscript.spec file that PyInstaller writes the first
> time you run it for your script. In the spec file you can tell PyInstaller
> about code and data files that are unique to your script.
>   * You can write "hook" files that inform PyInstaller of hidden imports. If
> you "hook" imports for a package that other users might also use, you can
> contribute your hook file to PyInstaller.
>

I also recommend py2exe, if PyInstaller won't meet Your needs.

