2

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)
user2726363
  • 31
  • 1
  • 4

1 Answers1

1

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.

HankMoody
  • 3,077
  • 1
  • 17
  • 38
  • Thank you so much. After importing django.test HTMLParser also pop'ed up as an error, but importing that, and everything is running. – user2726363 Aug 28 '13 at 20:24
  • When trying to run my actual project (with views and database) I get the error: ImproperlyConfigured: Error importing email backend module django.core.mail.backends.smtp: "No module named smtp" – user2726363 Aug 28 '13 at 21:47
  • If You want to send e-mails, then You need to include the missing modules in Your build (maybe just `import django.core.mail.backends` in `manage.py`?). If You don't want to send e-mail, then set `EMAIL_BACKEND` in your settings to `'django.core.mail.backends.dummy.EmailBackend'`. – HankMoody Aug 28 '13 at 22:08
  • Thank you once again. Maybe also you can also help with the next one: `AttributeError: 'set' object has no attribute 'rsplit'` – user2726363 Aug 28 '13 at 22:24
  • Don't have idea, seems like a bug in Your code, but can't tell without more info. – HankMoody Aug 28 '13 at 22:32
  • Okay. Thank you anyway. The project works fine until compiling it with pyinstaller and trying to run the .exe server . But will try leaving some parts of the code out and see when it starts working :) – user2726363 Aug 28 '13 at 22:36