Estimados, he desarrollado una app con django, pero ahora se me presento un problema al querer compilar a binario (.exe). Estoy usando Django + PyInstaller, si bien puedo llegar a obtener el binario, pero al ejecutarlo se produce un error que obstruye la ejecución de la app.
Cuando ejecuto : Django + PyInstaller el .exe no hace nada, se cierra rapidamente,no puedo ver el error y no activa el servidor ( #> mysite.exe runserver 127.0.0.1:8000)
Detalle de la compilación con PyInstaller
C:\DjangoCRM>pyinstaller --name=mysite manage.py
140 INFO: PyInstaller: 3.2
140 INFO: Python: 3.5.3
140 INFO: Platform: Windows-7-6.1.7601-SP1
140 INFO: wrote C:\DjangoCRM\mysite.spec
140 INFO: UPX is not available.
140 INFO: Extending PYTHONPATH with paths
['C:\\DjangoCRM', 'C:\\DjangoCRM']
140 INFO: checking Analysis
140 INFO: Building Analysis because out00-Analysis.toc is non existent
140 INFO: Initializing module dependency graph...
148 INFO: Initializing module graph hooks...
148 INFO: Analyzing base_library.zip ...
2048 INFO: running Analysis out00-Analysis.toc
2057 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of f
inal executable
required by C:\Users\AppData\Local\Programs\Python\Python35-32\python.
exe
2101 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:\Users\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\pyinstaller-3.2-py3.5.egg\PyInstaller\depend\bindepend.py", line 695, in ge
tImports
return _getImports_pe(pth)
File "C:\Users\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\pyinstaller-3.2-py3.5.egg\PyInstaller\depend\bindepend.py", line 122, in _g
etImports_pe
dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
2449 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:\Users\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\pyinstaller-3.2-py3.5.egg\PyInstaller\depend\bindepend.py", line 695, in ge
tImports
return _getImports_pe(pth)
File "C:\Users\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\pyinstaller-3.2-py3.5.egg\PyInstaller\depend\bindepend.py", line 122, in _g
etImports_pe
dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
2449 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:\Users\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\pyinstaller-3.2-py3.5.egg\PyInstaller\depend\bindepend.py", line 695, in ge
tImports
return _getImports_pe(pth)
File "C:\Users\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\pyinstaller-3.2-py3.5.egg\PyInstaller\depend\bindepend.py", line 122, in _g
etImports_pe
dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
2494 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:\Users\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\pyinstaller-3.2-py3.5.egg\PyInstaller\depend\bindepend.py", line 695, in ge
tImports
return _getImports_pe(pth)
File "C:\Users\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\pyinstaller-3.2-py3.5.egg\PyInstaller\depend\bindepend.py", line 122, in _g
etImports_pe
dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
2529 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:\Users\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\pyinstaller-3.2-py3.5.egg\PyInstaller\depend\bindepend.py", line 695, in ge
tImports
return _getImports_pe(pth)
File "C:\Users\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\pyinstaller-3.2-py3.5.egg\PyInstaller\depend\bindepend.py", line 122, in _g
etImports_pe
dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
2529 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:\Users\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\pyinstaller-3.2-py3.5.egg\PyInstaller\depend\bindepend.py", line 695, in ge
tImports
return _getImports_pe(pth)
File "C:\Users\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\pyinstaller-3.2-py3.5.egg\PyInstaller\depend\bindepend.py", line 122, in _g
etImports_pe
dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
2556 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:\Users\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\pyinstaller-3.2-py3.5.egg\PyInstaller\depend\bindepend.py", line 695, in ge
tImports
return _getImports_pe(pth)
File "C:\Users\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\pyinstaller-3.2-py3.5.egg\PyInstaller\depend\bindepend.py", line 122, in _g
etImports_pe
dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
2565 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:\Users\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\pyinstaller-3.2-py3.5.egg\PyInstaller\depend\bindepend.py", line 695, in ge
tImports
return _getImports_pe(pth)
File "C:\Users\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\pyinstaller-3.2-py3.5.egg\PyInstaller\depend\bindepend.py", line 122, in _g
etImports_pe
dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
2574 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:\Users\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\pyinstaller-3.2-py3.5.egg\PyInstaller\depend\bindepend.py", line 695, in ge
tImports
return _getImports_pe(pth)
File "C:\Users\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\pyinstaller-3.2-py3.5.egg\PyInstaller\depend\bindepend.py", line 122, in _g
etImports_pe
dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
2583 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:\Users\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\pyinstaller-3.2-py3.5.egg\PyInstaller\depend\bindepend.py", line 695, in ge
tImports
return _getImports_pe(pth)
File "C:\Users\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\pyinstaller-3.2-py3.5.egg\PyInstaller\depend\bindepend.py", line 122, in _g
etImports_pe
dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
2592 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:\Users\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\pyinstaller-3.2-py3.5.egg\PyInstaller\depend\bindepend.py", line 695, in ge
tImports
return _getImports_pe(pth)
File "C:\Users\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\pyinstaller-3.2-py3.5.egg\PyInstaller\depend\bindepend.py", line 122, in _g
etImports_pe
dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
2601 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:\Users\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\pyinstaller-3.2-py3.5.egg\PyInstaller\depend\bindepend.py", line 695, in ge
tImports
return _getImports_pe(pth)
File "C:\Users\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\pyinstaller-3.2-py3.5.egg\PyInstaller\depend\bindepend.py", line 122, in _g
etImports_pe
dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
2601 INFO: Caching module hooks...
2601 INFO: Analyzing C:\DjangoCRM\manage.py
3132 INFO: Processing pre-find module path hook distutils
5234 INFO: Loading module hooks...
5234 INFO: Loading module hook "hook-django.core.cache.py"...
5287 INFO: Loading module hook "hook-encodings.py"...
5296 INFO: Loading module hook "hook-lib2to3.py"...
5305 INFO: Loading module hook "hook-pkg_resources.py"...
5385 INFO: Processing pre-safe import module hook win32com
5569 INFO: Loading module hook "hook-django.core.management.py"...
6568 INFO: Import to be excluded not found: 'matplotlib'
6568 INFO: Import to be excluded not found: 'tkinter'
6568 INFO: Excluding import 'IPython'
6568 WARNING: Removing import django.core.management.commands.shell from modul
e IPython
6568 WARNING: Removing import django.core.management.commands.shell from modul
e IPython.start_ipython
6568 INFO: Loading module hook "hook-django.py"...
6568 INFO: Django root directory C:\DjangoCRM\DjangoCRM
Traceback (most recent call last):
File "C:\Users\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\pyinstaller-3.2-py3.5.egg\PyInstaller\utils\hooks\subproc\django_import_fin
der.py", line 37, in <module>
list(settings.TEMPLATE_LOADERS) + \
File "C:\Users\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\django\conf\__init__.py", line 57, in __getattr__
val = getattr(self._wrapped, name)
AttributeError: 'Settings' object has no attribute 'TEMPLATE_CONTEXT_PROCESSORS'
7818 INFO: Collecting Django migration scripts.
8610 INFO: Loading module hook "hook-sysconfig.py"...
8610 INFO: Loading module hook "hook-xml.py"...
8620 INFO: Loading module hook "hook-django.db.backends.py"...
8953 WARNING: Hidden import "django.db.backends.__pycache__.base" not found!
8953 INFO: Loading module hook "hook-xml.dom.domreg.py"...
8963 INFO: Loading module hook "hook-pythoncom.py"...
9169 INFO: Loading module hook "hook-sqlite3.py"...
9179 INFO: Loading module hook "hook-pytz.py"...
9326 INFO: Loading module hook "hook-pywintypes.py"...
9522 INFO: Loading module hook "hook-win32com.py"...
9816 INFO: Loading module hook "hook-pydoc.py"...
9816 INFO: Loading module hook "hook-django.core.mail.py"...
9856 INFO: Loading module hook "hook-distutils.py"...
9856 INFO: Loading module hook "hook-django.db.backends.mysql.base.py"...
9856 INFO: Loading module hook "hook-django.db.backends.oracle.base.py"...
9964 INFO: Looking for ctypes DLLs
9973 INFO: Analyzing run-time hooks ...
9983 INFO: Including run-time hook 'pyi_rth_django.py'
9983 INFO: Including run-time hook 'pyi_rth_pkgres.py'
9983 INFO: Including run-time hook 'pyi_rth_win32comgenpy.py'
10003 INFO: Looking for dynamic libraries
11777 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:\Users\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\pyinstaller-3.2-py3.5.egg\PyInstaller\depend\bindepend.py", line 695, in ge
tImports
return _getImports_pe(pth)
File "C:\Users\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\pyinstaller-3.2-py3.5.egg\PyInstaller\depend\bindepend.py", line 122, in _g
etImports_pe
dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
12189 WARNING: Can not get binary dependencies for file: C:\Windows\system32\api
-ms-win-crt-multibyte-l1-1-0.dll
Traceback (most recent call last):
File "C:\Users\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\pyinstaller-3.2-py3.5.egg\PyInstaller\depend\bindepend.py", line 695, in ge
tImports
return _getImports_pe(pth)
File "C:\Users\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\pyinstaller-3.2-py3.5.egg\PyInstaller\depend\bindepend.py", line 122, in _g
etImports_pe
dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
12189 INFO: Looking for eggs
12189 INFO: Using Python library C:\Users\AppData\Local\Programs\Python\
Python35-32\python35.dll
12189 INFO: Found binding redirects:
[]
12209 INFO: Warnings written to C:\DjangoCRM\build\mysite\warnmysite.txt
12356 INFO: checking PYZ
12356 INFO: Building PYZ because out00-PYZ.toc is non existent
12356 INFO: Building PYZ (ZlibArchive) C:\DjangoCRM\build\mysite\out00-PYZ.pyz
13989 INFO: checking PKG
13989 INFO: Building PKG because out00-PKG.toc is non existent
13999 INFO: Building PKG (CArchive) out00-PKG.pkg
14028 INFO: Bootloader C:\Users\AppData\Local\Programs\Python\Python35-3
2\lib\site-packages\pyinstaller-3.2-py3.5.egg\PyInstaller\bootloader\Windows-32b
it\run.exe
14038 INFO: checking EXE
14038 INFO: Building EXE because out00-EXE.toc is non existent
14038 INFO: Building EXE from out00-EXE.toc
14038 INFO: Appending archive to EXE C:\DjangoCRM\build\mysite\mysite.exe
14058 INFO: checking COLLECT
14058 INFO: Building COLLECT because out00-COLLECT.toc is non existent
14058 INFO: Building COLLECT out00-COLLECT.toc
Despues de tanto buscar, el problema estaba en encontrar como importar los archivos "hidden" que contiene el directorio hook de pyinstaller. Lo que hice fue crear un archivo como lo explica @FJSevilla y agregar el siguiente script:
#-----------------------------------------------------------------------------
# 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 = [
"dns.rdtypes.*",
"dns.rdtypes.ANY.*",
"django.contrib",
"django.contrib.admin.apps",
"django.contrib.auth.apps",
"django.contrib.contenttypes.apps",
"django.contrib.sessions.models",
"django.contrib.sessions.apps"
]
Pero ahora surge otro problema, el servidor sigue sin ejecutarse y me muestra el siguiente error:
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.
May 23, 2017 - 19:35:32
Django version 1.11.1, using settings 'DjangoCRM.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Unhandled exception in thread started by <function check_errors.<locals>.wrapper
at 0x02C06348>
Traceback (most recent call last):
File "site-packages\django\core\servers\basehttp.py", line 47, in get_internal
_wsgi_application
File "site-packages\django\utils\module_loading.py", line 20, in import_string
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 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
File "<frozen importlib._bootstrap>", line 634, in _load_backward_compatible
File "C:\Users\Carrito\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\pyinstaller-3.2.1-py3.5.egg\PyInstaller\loader\pyimod03_importers.py", line
389, in load_module
exec(bytecode, module.__dict__)
File "DjangoCRM\wsgi.py", line 16, in <module>
File "site-packages\django\core\wsgi.py", line 14, in get_wsgi_application
File "site-packages\django\core\handlers\wsgi.py", line 151, in __init__
File "site-packages\django\core\handlers\base.py", line 80, in load_middleware
File "site-packages\django\utils\module_loading.py", line 20, in import_string
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.messages.middleware'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "site-packages\django\utils\autoreload.py", line 227, in wrapper
File "site-packages\django\core\management\commands\runserver.py", line 147, i
n inner_run
File "site-packages\django\core\management\commands\runserver.py", line 68, in
get_handler
File "site-packages\django\core\servers\basehttp.py", line 57, in get_internal
_wsgi_application
File "site-packages\django\utils\six.py", line 685, in reraise
File "site-packages\django\core\servers\basehttp.py", line 47, in get_internal
_wsgi_application
File "site-packages\django\utils\module_loading.py", line 20, in import_string
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 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
File "<frozen importlib._bootstrap>", line 634, in _load_backward_compatible
File "C:\Users\Carrito\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\pyinstaller-3.2.1-py3.5.egg\PyInstaller\loader\pyimod03_importers.py", line
389, in load_module
exec(bytecode, module.__dict__)
File "DjangoCRM\wsgi.py", line 16, in <module>
File "site-packages\django\core\wsgi.py", line 14, in get_wsgi_application
File "site-packages\django\core\handlers\wsgi.py", line 151, in __init__
File "site-packages\django\core\handlers\base.py", line 80, in load_middleware
File "site-packages\django\utils\module_loading.py", line 20, in import_string
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
django.core.exceptions.ImproperlyConfigured: WSGI application 'DjangoCRM.wsgi.ap
plication' could not be loaded; Error importing module: 'No module named 'django
.contrib.messages.middleware''
Quiero saber si alguien tuvo el mismo problema o me puede dar una idea de cual puede ser el error.