我正在尝试编译Django(1.8)应用程序,它在Windows 7上有2个自定义命令。 我们使用pandas和其他sci libs,所以我们通过anaconda3运行应用程序。
当我们使用Pyinstaller(版本3.0,通过anaconda pip脚本添加到anaconda3)时:
c:\Anaconda3\Scripts\pyinstaller.exe --name=compileTest --exclude-module=PyQt4 --exclude-module=matplotlib manage.py
我们得到一个Django可执行项目但没有自定义命令。
有人可以建议吗?
答案 0 :(得分:1)
这通过包含/覆盖django运行时挂钩为我工作。
https://pythonhosted.org/PyInstaller/#changing-runtime-behavior
将--runtime-hook=pyi_rth_django.py
添加到PyInstaller命令。
<强> pyi_rth_django.py 强>
注意添加的omnibusd
命令。
# This Django rthook was tested with Django 1.8.3.
import django.core.management
import django.utils.autoreload
def _get_commands():
# Django groupss commands by app.
# This returns static dict() as it is for django 1.8 and the default project.
commands = {
'runserver': 'django.core',
'shell': 'django.core',
'startapp': 'django.core',
'startproject': 'django.core',
'test': 'django.core',
'testserver': 'django.core',
'validate': 'django.core',
'omnibusd': 'omnibus'
}
return commands
_old_restart_with_reloader = django.utils.autoreload.restart_with_reloader
def _restart_with_reloader(*args):
import sys
a0 = sys.argv.pop(0)
try:
return _old_restart_with_reloader(*args)
finally:
sys.argv.insert(0, a0)
# Override get_commands() function otherwise the app will complain that
# there are no commands.
django.core.management.get_commands = _get_commands
# Override restart_with_reloader() function otherwise the app might
# complain that some commands do not exist. e.g. runserver.
django.utils.autoreload.restart_with_reloader = _restart_with_reloader