安装了Django 1.10.4并以名称test_py启动了一个项目。之后,通过名称test_app1创建了一个应用程序。
创建计划创建安装程序的应用程序后,将其作为标准应用程序运行。
尝试使用Django 1.10.4和pyinstaller 3.2制作Windows安装程序 执行以下命令时出现错误,然后是控制台输出。
$pyinstaller --name=test_py ../test_py/manage.py
131 INFO: PyInstaller: 3.2
131 INFO: Python: 2.7.12
131 INFO: Platform: Windows-7-6.1.7601-SP1
132 INFO: wrote C:\MAMP\htdocs\crumbles\test_django\test_py_package\test_py.spec
134 INFO: UPX is not available.
137 INFO: Extending PYTHONPATH with paths
['C:\\MAMP\\htdocs\\crumbles\\test_django\\test_py',
'C:\\MAMP\\htdocs\\crumbles\\test_django\\test_py_package']
137 INFO: checking Analysis
137 INFO: Building Analysis because out00-Analysis.toc is non existent
137 INFO: Initializing module dependency graph...
140 INFO: Initializing module graph hooks...
203 INFO: running Analysis out00-Analysis.toc
208 INFO: Adding Microsoft.VC90.CRT to dependent assemblies of final executable
required by c:\python27\python.exe
328 INFO: Found C:\Windows\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.1_none_3da38fdebd0e6822.manifest
330 INFO: Found C:\Windows\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4926_none_accf10dbe1dc8ba2.manifest
332 INFO: Found C:\Windows\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4940_none_acd19a1fe1da248a.manifest
435 INFO: Searching for assembly amd64_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.4940_none ...
435 INFO: Found manifest C:\Windows\WinSxS\Manifests\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4940_none_08e4299fa83d7e3c.manifest
437 INFO: Searching for file msvcr90.dll
437 INFO: Found file C:\Windows\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4940_none_08e4299fa83d7e3c\msvcr90.dll
437 INFO: Searching for file msvcp90.dll
437 INFO: Found file C:\Windows\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4940_none_08e4299fa83d7e3c\msvcp90.dll
437 INFO: Searching for file msvcm90.dll
437 INFO: Found file C:\Windows\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4940_none_08e4299fa83d7e3c\msvcm90.dll
545 INFO: Found C:\Windows\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.1_none_3da38fdebd0e6822.manifest
546 INFO: Found C:\Windows\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4926_none_accf10dbe1dc8ba2.manifest
547 INFO: Found C:\Windows\WinSxS\Manifests \amd64_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4940_none_acd19a1fe1da248a.manifest
548 INFO: Adding redirect Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 30729, 4940)
5515 INFO: Caching module hooks...
5520 INFO: Analyzing C:\MAMP\htdocs\crumbles\test_django\test_py\manage.py
8648 INFO: Processing pre-find module path hook distutils
8905 INFO: Processing pre-safe import module hook _xmlplus
12407 INFO: Loading module hooks...
12407 INFO: Loading module hook "hook-distutils.py"...
12407 INFO: Loading module hook "hook-sysconfig.py"...
12407 INFO: Loading module hook "hook-django.core.management.py"...
14320 INFO: Excluding import 'IPython'
14322 WARNING: Removing import django.core.management.commands.shell from module IPython
14322 WARNING: Removing import django.core.management.commands.shell from module IPython.IPShell
14322 WARNING: Removing import django.core.management.commands.shell from module IPython.start_ipython
14323 INFO: Import to be excluded not found: 'Tkinter'
14323 INFO: Import to be excluded not found: 'matplotlib'
14324 INFO: Loading module hook "hook-xml.py"...
14324 INFO: Loading module hook "hook-django.db.backends.py"...
15119 INFO: Loading module hook "hook-jinja2.py"...
15141 INFO: Loading module hook "hook-httplib.py"...
15141 INFO: Loading module hook "hook-django.db.backends.oracle.base.py"...
15144 INFO: Loading module hook "hook-xml.dom.domreg.py"...
15144 INFO: Loading module hook "hook-pkg_resources.py"...
15457 INFO: Loading module hook "hook-django.db.backends.mysql.base.py"...
15459 INFO: Loading module hook "hook-django.core.mail.py"...
15537 INFO: Loading module hook "hook-pytz.py"...
15617 INFO: Loading module hook "hook-encodings.py"...
16035 INFO: Loading module hook "hook-sqlite3.py"...
16040 INFO: Loading module hook "hook-django.py"...
16041 INFO: Django root directory C:\MAMP\htdocs\crumbles\test_django\test_py\test_py
Traceback (most recent call last):
File "c:\python27\lib\site-packages\PyInstaller\utils\hooks\subproc\django_import_finder.py", line 37, in <module>
list(settings.TEMPLATE_LOADERS) + \
File "c:\python27\lib\site-packages\django\conf\__init__.py", line 54, in __getattr__
return getattr(self._wrapped, name)
AttributeError: 'Settings' object has no attribute 'TEMPLATE_CONTEXT_PROCESSORS'
17037 INFO: Collecting Django migration scripts.
18081 INFO: Loading module hook "hook-django.core.cache.py"...
18119 INFO: Loading module hook "hook-psycopg2.py"...
18121 WARNING: Hidden import "mx.DateTime" not found!
18186 INFO: Looking for ctypes DLLs
18203 INFO: Analyzing run-time hooks ...
18215 INFO: Including run-time hook 'pyi_rth_django.py'
18217 INFO: Including run-time hook 'pyi_rth_pkgres.py'
18242 INFO: Looking for dynamic libraries
32332 INFO: Looking for eggs
32332 INFO: Using Python library C:\Windows\system32\python27.dll
32332 INFO: Found binding redirects:
[BindingRedirect(name=u'Microsoft.VC90.CRT', language=None, arch=u'amd64', oldVersion=(9, 0, 21022, 8), newVersion=(9, 0, 30729, 4940), publicKeyToken=u'1fc8b3b9a1e18e3b')]
32357 INFO: Warnings written to C:\MAMP\htdocs\crumbles\test_django\test_py_package\build\test_py\warntest_py.txt
33626 INFO: checking PYZ
33627 INFO: Building PYZ because out00-PYZ.toc is non existent
33627 INFO: Building PYZ (ZlibArchive) C:\MAMP\htdocs\crumbles\test_django\test_py_package\build\test_py\out00-PYZ.pyz
35328 INFO: checking PKG
35328 INFO: Building PKG because out00-PKG.toc is non existent
35328 INFO: Building PKG (CArchive) out00-PKG.pkg
35485 INFO: Bootloader c:\python27\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
35485 INFO: checking EXE
35486 INFO: Building EXE because out00-EXE.toc is non existent
35486 INFO: Building EXE from out00-EXE.toc
35486 INFO: Appending archive to EXE C:\MAMP\htdocs\crumbles\test_django\test_py_package\build\test_py\test_py.exe
35518 INFO: checking COLLECT
35518 INFO: Building COLLECT because out00-COLLECT.toc is non existent
35518 INFO: Building COLLECT out00-COLLECT.toc
35543 INFO: Redirecting Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 30729, 4940)
答案 0 :(得分:2)
Django 1.8中不推荐xib
设置,Django 1.10中删除了TEMPLATE_CONTEXT_PROCESSORS
设置。
看起来好像pyinstaller不支持Django 1.10(参见this issue)。在修复之前,你可以使用Django 1.8,这是一个LTS(长期支持)版本。
答案 1 :(得分:0)
打开位于django_import_finder.py
的文件C:\Users\<username>\AppData\Local\Programs\Python\Python37\Lib\site-packages\PyInstaller\utils\hooks\subproc
文件
找到名为“ hiddenimports”
的变量hiddenimports = list("settings.INSTALLED_APPS") + \
list("settings.TEMPLATE_CONTEXT_PROCESSORS") + \
list("settings.TEMPLATE_LOADERS") + \
["settings.ROOT_URLCONF"]
用以下几行替换上述变量数据
hiddenimports = list(getattr(settings, "INSTALLED_APPS", [])) + \
list(getattr(settings, "TEMPLATE_CONTEXT_PROCESSORS", [])) + \
list(getattr(settings, "TEMPLATE_LOADERS", [])) + \
[getattr(settings, "ROOT_URLCONF", "")]
此解决方案来自https://gist.github.com/sadnoodles/ceb13afe8dfcf40e92adc0dfbafface2