Pyinstaller Error for Djnago project "ImportError: No module named 'django.contrib.admin.apps'"

I have created one project in django.I have created installer for it using pyinstaller.If I run project using python manage.py runserver then project is running fine without any error,but I am not able to run it through installer. I am getting error while running installer.

C:\The_Incredibles\Pyinstaller Story\test_proj>.\dist\demo\demo.exe runserver
Unhandled exception in thread started by <function check_errors.<locals>.wrapper
 at 0x03A15978>
Traceback (most recent call last):
  File "site-packages\django-1.10.4-py3.5.egg\django\utils\autoreload.py", line
226, in wrapper
  File "site-packages\django-1.10.4-py3.5.egg\django\core\management\commands\ru
nserver.py", line 113, in inner_run
  File "site-packages\django-1.10.4-py3.5.egg\django\utils\autoreload.py", line
249, in raise_last_exception
  File "site-packages\django-1.10.4-py3.5.egg\django\utils\six.py", line 685, in
 reraise
  File "site-packages\django-1.10.4-py3.5.egg\django\utils\autoreload.py", line
226, in wrapper
  File "site-packages\django-1.10.4-py3.5.egg\django\__init__.py", line 27, in s
etup
  File "site-packages\django-1.10.4-py3.5.egg\django\apps\registry.py", line 85,
 in populate
  File "site-packages\django-1.10.4-py3.5.egg\django\apps\config.py", line 116,
in create
  File "importlib\__init__.py", line 126, in import_module
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
ImportError: No module named 'django.contrib.admin.apps'

demo.spec

# -*- mode: python -*-

block_cipher = None


a = Analysis(['test1\\manage.py'],
             pathex=['C:\\The_Incredibles\\Pyinstaller Story\\test_proj'],
             binaries=None,
             datas=None,
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          exclude_binaries=True,
          name='demo',
          debug=False,
          strip=False,
          upx=True,
          console=True )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               name='demo')

Here is PyInstaller log

(Sample) C:\The_Incredibles\Pyinstaller Story\test_proj>pyinstaller --name=demo
test1/manage.py
155 INFO: PyInstaller: 3.2
155 INFO: Python: 3.5.2
155 INFO: Platform: Windows-7-6.1.7601-SP1
157 INFO: wrote C:\The_Incredibles\Pyinstaller Story\test_proj\demo.spec
159 INFO: UPX is not available.
168 INFO: Extending PYTHONPATH with paths
['C:\\The_Incredibles\\Pyinstaller Story\\test_proj\\test1',
 'C:\\The_Incredibles\\Pyinstaller Story\\test_proj']
168 INFO: checking Analysis
169 INFO: Building Analysis because out00-Analysis.toc is non existent
169 INFO: Initializing module dependency graph...
172 INFO: Initializing module graph hooks...
175 INFO: Analyzing base_library.zip ...
2829 INFO: running Analysis out00-Analysis.toc
2943 WARNING: Can not get binary dependencies for file: C:\windows\system32\api-
ms-win-crt-math-l1-1-0.dll
Traceback (most recent call last):
  File "c:\python\scripts\sample\lib\site-packages\PyInstaller\depend\bindepend.
py", line 695, in getImports
    return _getImports_pe(pth)
  File "c:\python\scripts\sample\lib\site-packages\PyInstaller\depend\bindepend.
py", line 122, in _getImports_pe
    dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
3431 WARNING: Can not get binary dependencies for file: C:\windows\system32\api-
ms-win-crt-runtime-l1-1-0.dll
Traceback (most recent call last):
  File "c:\python\scripts\sample\lib\site-packages\PyInstaller\depend\bindepend.
py", line 695, in getImports
    return _getImports_pe(pth)
  File "c:\python\scripts\sample\lib\site-packages\PyInstaller\depend\bindepend.
py", line 122, in _getImports_pe
    dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
3438 WARNING: Can not get binary dependencies for file: C:\windows\system32\api-
ms-win-crt-locale-l1-1-0.dll
Traceback (most recent call last):
  File "c:\python\scripts\sample\lib\site-packages\PyInstaller\depend\bindepend.
py", line 695, in getImports
    return _getImports_pe(pth)
  File "c:\python\scripts\sample\lib\site-packages\PyInstaller\depend\bindepend.
py", line 122, in _getImports_pe
    dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
3445 WARNING: Can not get binary dependencies for file: C:\windows\system32\api-
ms-win-crt-heap-l1-1-0.dll
Traceback (most recent call last):
  File "c:\python\scripts\sample\lib\site-packages\PyInstaller\depend\bindepend.
py", line 695, in getImports
    return _getImports_pe(pth)
  File "c:\python\scripts\sample\lib\site-packages\PyInstaller\depend\bindepend.
py", line 122, in _getImports_pe
    dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
3472 WARNING: Can not get binary dependencies for file: C:\windows\system32\api-
ms-win-crt-stdio-l1-1-0.dll
Traceback (most recent call last):
  File "c:\python\scripts\sample\lib\site-packages\PyInstaller\depend\bindepend.
py", line 695, in getImports
    return _getImports_pe(pth)
  File "c:\python\scripts\sample\lib\site-packages\PyInstaller\depend\bindepend.
py", line 122, in _getImports_pe
    dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
3481 WARNING: Can not get binary dependencies for file: C:\windows\system32\api-
ms-win-crt-process-l1-1-0.dll
Traceback (most recent call last):
  File "c:\python\scripts\sample\lib\site-packages\PyInstaller\depend\bindepend.
py", line 695, in getImports
    return _getImports_pe(pth)
  File "c:\python\scripts\sample\lib\site-packages\PyInstaller\depend\bindepend.
py", line 122, in _getImports_pe
    dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
3506 WARNING: Can not get binary dependencies for file: C:\windows\system32\api-
ms-win-crt-string-l1-1-0.dll
Traceback (most recent call last):
  File "c:\python\scripts\sample\lib\site-packages\PyInstaller\depend\bindepend.
py", line 695, in getImports
    return _getImports_pe(pth)
  File "c:\python\scripts\sample\lib\site-packages\PyInstaller\depend\bindepend.
py", line 122, in _getImports_pe
    dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
3519 WARNING: Can not get binary dependencies for file: C:\windows\system32\api-
ms-win-crt-time-l1-1-0.dll
Traceback (most recent call last):
  File "c:\python\scripts\sample\lib\site-packages\PyInstaller\depend\bindepend.
py", line 695, in getImports
    return _getImports_pe(pth)
  File "c:\python\scripts\sample\lib\site-packages\PyInstaller\depend\bindepend.
py", line 122, in _getImports_pe
    dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
3525 WARNING: Can not get binary dependencies for file: C:\windows\system32\api-
ms-win-crt-environment-l1-1-0.dll
Traceback (most recent call last):
  File "c:\python\scripts\sample\lib\site-packages\PyInstaller\depend\bindepend.
py", line 695, in getImports
    return _getImports_pe(pth)
  File "c:\python\scripts\sample\lib\site-packages\PyInstaller\depend\bindepend.
py", line 122, in _getImports_pe
    dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
3545 WARNING: Can not get binary dependencies for file: C:\windows\system32\api-
ms-win-crt-convert-l1-1-0.dll
Traceback (most recent call last):
  File "c:\python\scripts\sample\lib\site-packages\PyInstaller\depend\bindepend.
py", line 695, in getImports
    return _getImports_pe(pth)
  File "c:\python\scripts\sample\lib\site-packages\PyInstaller\depend\bindepend.
py", line 122, in _getImports_pe
    dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
3552 WARNING: Can not get binary dependencies for file: C:\windows\system32\api-
ms-win-crt-conio-l1-1-0.dll
Traceback (most recent call last):
  File "c:\python\scripts\sample\lib\site-packages\PyInstaller\depend\bindepend.
py", line 695, in getImports
    return _getImports_pe(pth)
  File "c:\python\scripts\sample\lib\site-packages\PyInstaller\depend\bindepend.
py", line 122, in _getImports_pe
    dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
3564 WARNING: Can not get binary dependencies for file: C:\windows\system32\api-
ms-win-crt-filesystem-l1-1-0.dll
Traceback (most recent call last):
  File "c:\python\scripts\sample\lib\site-packages\PyInstaller\depend\bindepend.
py", line 695, in getImports
    return _getImports_pe(pth)
  File "c:\python\scripts\sample\lib\site-packages\PyInstaller\depend\bindepend.
py", line 122, in _getImports_pe
    dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
3567 INFO: Caching module hooks...
3572 INFO: Analyzing C:\The_Incredibles\Pyinstaller Story\test_proj\test1\manage
.py
6478 INFO: Loading module hooks...
6478 INFO: Loading module hook "hook-django.core.management.py"...
7684 INFO: Import to be excluded not found: 'matplotlib'
7685 INFO: Import to be excluded not found: 'tkinter'
7685 INFO: Excluding import 'IPython'
7688 WARNING:   Removing import django.core.management.commands.shell from modul
e IPython
7689 WARNING:   Removing import django.core.management.commands.shell from modul
e IPython.start_ipython
7689 WARNING:   Removing import django.core.management.commands.shell from modul
e IPython.IPShell
7691 INFO: Loading module hook "hook-xml.py"...
7693 INFO: Loading module hook "hook-django.py"...
7694 INFO: Django root directory C:\The_Incredibles\Pyinstaller Story\test_proj\
test1\test1
Traceback (most recent call last):
  File "c:\python\scripts\sample\lib\site-packages\PyInstaller\utils\hooks\subpr
oc\django_import_finder.py", line 37, in <module>
    list(settings.TEMPLATE_LOADERS) + \
  File "c:\python\scripts\sample\lib\site-packages\django-1.10.4-py3.5.egg\djang
o\conf\__init__.py", line 54, in __getattr__
    return getattr(self._wrapped, name)
AttributeError: 'Settings' object has no attribute 'TEMPLATE_CONTEXT_PROCESSORS'

8910 INFO: Collecting Django migration scripts.
9818 INFO: Loading module hook "hook-django.core.mail.py"...
9880 INFO: Loading module hook "hook-encodings.py"...
9891 INFO: Loading module hook "hook-django.core.cache.py"...
9916 INFO: Loading module hook "hook-django.db.backends.py"...
10392 WARNING: Hidden import "django.db.backends.__pycache__.base" not found!
10393 INFO: Loading module hook "hook-pydoc.py"...
10395 INFO: Loading module hook "hook-xml.dom.domreg.py"...
10396 INFO: Loading module hook "hook-django.db.backends.oracle.base.py"...
10400 INFO: Loading module hook "hook-django.db.backends.mysql.base.py"...
10403 INFO: Loading module hook "hook-sqlite3.py"...
10478 INFO: checking Tree
10478 INFO: Building Tree because out00-Tree.toc is non existent
10479 INFO: Building Tree out00-Tree.toc
10969 INFO: Looking for ctypes DLLs
10986 INFO: Analyzing run-time hooks ...
10996 INFO: Including run-time hook 'pyi_rth_django.py'
11017 INFO: Looking for dynamic libraries
12997 WARNING: Can not get binary dependencies for file: C:\windows\system32\api
-ms-win-crt-utility-l1-1-0.dll
Traceback (most recent call last):
  File "c:\python\scripts\sample\lib\site-packages\PyInstaller\depend\bindepend.
py", line 695, in getImports
    return _getImports_pe(pth)
  File "c:\python\scripts\sample\lib\site-packages\PyInstaller\depend\bindepend.
py", line 122, in _getImports_pe
    dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
12998 INFO: Looking for eggs
12999 INFO: Using Python library c:\python\scripts\sample\scripts\python35.dll
12999 INFO: Found binding redirects:
[]
13018 INFO: Warnings written to C:\The_Incredibles\Pyinstaller Story\test_proj\b
uild\demo\warndemo.txt
13157 INFO: checking PYZ
13158 INFO: Building PYZ because out00-PYZ.toc is non existent
13158 INFO: Building PYZ (ZlibArchive) C:\The_Incredibles\Pyinstaller Story\test
_proj\build\demo\out00-PYZ.pyz
14732 INFO: checking PKG
14732 INFO: Building PKG because out00-PKG.toc is non existent
14733 INFO: Building PKG (CArchive) out00-PKG.pkg
14784 INFO: Bootloader c:\python\scripts\sample\lib\site-packages\PyInstaller\bo
otloader\Windows-32bit\run.exe
14785 INFO: checking EXE
14785 INFO: Building EXE because out00-EXE.toc is non existent
14785 INFO: Building EXE from out00-EXE.toc
14786 INFO: Appending archive to EXE C:\The_Incredibles\Pyinstaller Story\test_p
roj\build\demo\demo.exe
14807 INFO: checking COLLECT
14808 INFO: Building COLLECT because out00-COLLECT.toc is non existent
14808 INFO: Building COLLECT out00-COLLECT.toc

(Sample) C:\The_Incredibles\Pyinstaller Story\test_proj>


ANSWERS:


My issue get resolved. The problem was pyinstaller not able to import all hidden imports.What I did I added one hookfile(hook-django.contrib.py) under Lib\site-packages\PyInstaller\hooks.

added following code to hookfile

#-----------------------------------------------------------------------------
# Copyright (c) 2005-2016, PyInstaller Development Team.
#
# Distributed under the terms of the GNU General Public License with exception
# for distributing bootloader.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------

from PyInstaller.utils.hooks import collect_submodules
hiddenimports = collect_submodules('django.contrib')

This worked for Me. I have created exe file from my djnago project using pyinstaller and I am able to run my project using exe.

output after running exe file

(DemoEnv) C:\The_Incredibles\Pyinstaller Story\test_project>dist\manage\manage.e
xe runserver
Performing system checks...

System check identified no issues (0 silenced).

You have 13 unapplied migration(s). Your project may not work properly until you
 apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
December 29, 2016 - 10:45:08
Django version 1.10.4, using settings 'demo.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
[29/Dec/2016 10:45:26] "GET / HTTP/1.1" 200 1767


 MORE:


 ? In django, values(*field) doesn't give all values of ForeignKey field with sliced queryset
 ? Django migrations - default entries (inserting rows in tables as part of migration)
 ? Dynamically import url in Django gives 'str' object is not callable
 ? Django: Get user's input in textarea and display them on page
 ? How to set default css classes for all built-in form widgets in Django
 ? How to filter data by time on django?
 ? Making dictionary from two lists
 ? How does collectstatic work in Django?
 ? How to split render django's ModelMultipleChoiceField in template file?
 ? caching issues in MySQL response with MySQLdb in Django