问题
I am trying to package my django app with pyinstaller and I created this pyinstaller spec file for this purpose:
# -*- mode: python -*-
block_cipher = None
a = Analysis(['manage.py'],
pathex=['/home/gero/PycharmProjects/gen-optimizer-precision'],
binaries=None,
datas=None,
hiddenimports=[],
hookspath=None,
runtime_hooks=None,
excludes=['matplotlib'],
win_no_prefer_redirects=None,
win_private_assemblies=None,
cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
exclude_binaries=True,
name='optimizer',
debug=True,
strip=None,
upx=True,
console=True )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=None,
upx=True,
name='optimizer')
Here is the pyinstallers log:
39 INFO: PyInstaller: 3.0
: Python: 3.4.2
39 INFO: Platform: Linux-3.16.0-44-generic-x86_64-with-Ubuntu-14.10-utopic
41 INFO: UPX is not available.
41 INFO: Removing temporary files and cleaning cache in ~/.local/share/pyinstaller
47 INFO: Extending PYTHONPATH with ~/PycharmProjects/gen-optimizer-precision
47 INFO: checking Analysis
47 INFO: Building Analysis because out00-Analysis.toc is non existent
47 INFO: Initializing module dependency graph...
48 INFO: Initializing module graph hooks...
49 INFO: Analyzing base_library.zip ...
1336 INFO: Processing pre-find module path hook distutils
2482 INFO: running Analysis out00-Analysis.toc
2510 INFO: Analyzing manage.py
4420 INFO: Looking for import hooks ...
4422 INFO: Processing hook hook-django.template.loaders.py
5025 INFO: Processing hook hook-encodings.py
5033 INFO: Processing hook hook-django.db.backends.py
5408 WARNING: Hidden import 'django.db.backends.__pycache__.base' not found (probably old hook)
5503 INFO: Processing hook hook-distutils.py
5504 INFO: Processing hook hook-xml.py
5697 INFO: Processing hook hook-django.core.management.py
6317 INFO: Excluding import 'matplotlib'
6319 WARNING: Removing import 'matplotlib'
6319 INFO: Excluding import 'IPython'
6319 INFO: Excluded import 'tkinter' not found
6319 INFO: Processing hook hook-django.db.backends.mysql.base.py
6321 INFO: Processing hook hook-xml.dom.py
6322 INFO: Processing hook hook-django.py
6323 INFO: Django root directory ~/PycharmProjects/gen-optimizer-precision/genoptimizer
~/optimizer/lib/python3.4/site-packages/django/forms/models.py:1246: RemovedInDjango19Warning: cache_choices has been deprecated and will be removed in Django 1.9.
*args, **kwargs)
6964 INFO: Collecting Django migration scripts.
7027 WARNING: Hidden import 'django.contrib.messages.context_processors.messages' not found (probably old hook)
8465 INFO: Processing pre-find module path hook site
8466 INFO: site: retargeting to fake-dir '~/optimizer/lib/python3.4/site-packages/PyInstaller/fake-modules'
9558 WARNING: Hidden import 'optimizer.templatetags' not found (probably old hook)
9957 WARNING: Hidden import 'django.template.loaders.app_directories.Loader' not found (probably old hook)
9964 WARNING: Hidden import 'django.contrib.sessions.context_processors' not found (probably old hook)
10063 WARNING: Hidden import 'django.contrib.contenttypes.context_processors' not found (probably old hook)
10063 WARNING: Hidden import 'django.contrib.sessions.templatetags' not found (probably old hook)
10063 WARNING: Hidden import 'optimizer.context_processors' not found (probably old hook)
10063 WARNING: Hidden import 'django.contrib.auth.context_processors.auth' not found (probably old hook)
10063 WARNING: Hidden import 'csvimport.app.CSVImportConf' not found (probably old hook)
10146 WARNING: Hidden import 'suitlocale.templatetags' not found (probably old hook)
10148 WARNING: Hidden import 'django.template.context_processors.media' not found (probably old hook)
10149 WARNING: Hidden import 'django.contrib.contenttypes.templatetags' not found (probably old hook)
10149 WARNING: Hidden import 'genoptimizer.optemplates.templatetags' not found (probably old hook)
10149 WARNING: Hidden import 'django.contrib.staticfiles.context_processors' not found (probably old hook)
10399 WARNING: Hidden import 'crispy_forms.context_processors' not found (probably old hook)
10417 WARNING: Hidden import 'suit.context_processors' not found (probably old hook)
10417 WARNING: Hidden import 'genoptimizer.optemplates.context_processors' not found (probably old hook)
10442 WARNING: Hidden import 'django.template.context_processors.static' not found (probably old hook)
10442 WARNING: Hidden import 'django.template.context_processors.debug' not found (probably old hook)
10455 WARNING: Hidden import 'csvimport.app.CSVImportConf.templatetags' not found (probably old hook)
10455 WARNING: Hidden import 'django.template.context_processors.tz' not found (probably old hook)
10455 WARNING: Hidden import 'django.contrib.auth.templatetags' not found (probably old hook)
10455 WARNING: Hidden import 'csvimport.app.CSVImportConf.context_processors' not found (probably old hook)
10460 WARNING: Hidden import 'django.contrib.admin.context_processors' not found (probably old hook)
10461 WARNING: Hidden import 'suitlocale.context_processors' not found (probably old hook)
10461 WARNING: Hidden import 'django.contrib.messages.templatetags' not found (probably old hook)
10462 WARNING: Hidden import 'django.template.context_processors.i18n' not found (probably old hook)
10462 WARNING: Hidden import 'django.template.loaders.filesystem.Loader' not found (probably old hook)
10687 INFO: Processing hook hook-django.db.backends.oracle.base.py
10689 INFO: Processing hook hook-pydoc.py
10690 INFO: Processing hook hook-django.core.mail.py
10743 INFO: Processing hook hook-xml.sax.py
10743 INFO: Processing hook hook-setuptools.py
10744 INFO: Processing hook hook-xml.dom.domreg.py
10744 INFO: Processing hook hook-sqlite3.py
10747 INFO: Processing hook hook-sysconfig.py
10748 INFO: Processing hook hook-psycopg2.py
10748 WARNING: Hidden import 'mx.DateTime' not found (probably old hook)
10748 INFO: Processing hook hook-django.core.cache.py
10773 INFO: Processing hook hook-django.contrib.sessions.py
10826 INFO: Looking for ctypes DLLs
10863 WARNING: library rpcrt4.dll required via ctypes not found
10943 INFO: Analyzing run-time hooks ...
10959 INFO: Including run-time hook 'pyi_rth_pkgres.py'
10960 INFO: Including run-time hook 'pyi_rth_django.py'
10992 INFO: Looking for dynamic libraries
11644 INFO: Looking for eggs
11644 INFO: Python library not in binary depedencies. Doing additional searching...
11674 INFO: Using Python library /usr/lib/x86_64-linux-gnu/libpython3.4m.so.1.0
11707 INFO: Warnings written to ~/PycharmProjects/gen-optimizer-precision/build/optimizer/warnoptimizer.txt
11721 INFO: checking PYZ
11721 INFO: Building PYZ because out00-PYZ.toc is non existent
11721 INFO: Building PYZ (ZlibArchive) ~/PycharmProjects/gen-optimizer-precision/build/optimizer/out00-PYZ.pyz
12267 INFO: checking PKG
12267 INFO: Building PKG because out00-PKG.toc is non existent
12267 INFO: Building PKG (CArchive) out00-PKG.pkg
12308 INFO: Bootloader ~/optimizer/lib/python3.4/site-packages/PyInstaller/bootloader/Linux-64bit/run_d
12308 INFO: checking EXE
12308 INFO: Building EXE because out00-EXE.toc is non existent
12308 INFO: Building EXE from out00-EXE.toc
12308 INFO: Appending archive to EXE ~/PycharmProjects/gen-optimizer-precision/build/optimizer/optimizer
12322 INFO: checking COLLECT
12322 INFO: Building COLLECT because out00-COLLECT.toc is non existent
12322 INFO: Removing dir ~/PycharmProjects/gen-optimizer-precision/dist/optimizer
12473 INFO: Building COLLECT out00-COLLECT.toc
I am getting this error at runtime when I try to request the home page:
Starting development server at http://127.0.0.1:8002/
Quit the server with CONTROL-C.
Internal Server Error: /
Traceback (most recent call last):
File "~/optimizer/lib/python3.4/site-packages/django/core/handlers/base.py", line 132, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "~/PycharmProjects/gen-optimizer-precision/optimizer/views.py", line 52, in optimized_setup
return render(request, 'optimizer.html', {'form': form})
File "~/optimizer/lib/python3.4/site-packages/django/shortcuts.py", line 67, in render
template_name, context, request=request, using=using)
File "~/optimizer/lib/python3.4/site-packages/django/template/loader.py", line 99, in render_to_string
return template.render(context, request)
File "~/optimizer/lib/python3.4/site-packages/django/template/backends/django.py", line 74, in render
return self.template.render(context)
File "~/optimizer/lib/python3.4/site-packages/django/template/base.py", line 209, in render
with context.bind_template(self):
File "/usr/lib/python3.4/contextlib.py", line 59, in __enter__
return next(self.gen)
File "~/optimizer/lib/python3.4/site-packages/django/template/context.py", line 237, in bind_template
processors = (template.engine.template_context_processors +
File "~/optimizer/lib/python3.4/site-packages/django/utils/functional.py", line 59, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "~/optimizer/lib/python3.4/site-packages/django/template/engine.py", line 90, in template_context_processors
return tuple(import_string(path) for path in context_processors)
File "~/optimizer/lib/python3.4/site-packages/django/template/engine.py", line 90, in <genexpr>
return tuple(import_string(path) for path in context_processors)
File "~/optimizer/lib/python3.4/site-packages/django/utils/module_loading.py", line 26, in import_string
module = import_module(module_path)
File "/usr/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2224, in _find_and_load_unlocked
ImportError: No module named 'django.core.context_processors'
Any clues fellows?
回答1:
From docs:
Changed in Django 1.8:
Built-in template context processors were moved from django.core.context_processors to django.template.context_processors in Django 1.8.
Probably you are importing context_processors using the old path in ~/PycharmProjects/gen-optimizer-precision/optimizer/views.py
.
来源:https://stackoverflow.com/questions/33946710/pyinstaller-django-no-module-named-django-core-context-processors