runsslserver命令无法在django中使用pyinstaller构建的可执行文件

时间:2018-06-12 03:43:41

标签: python django pyinstaller

我正在使用runsslserver命令来运行django应用程序。在生成其可执行文件之前在命令行上运行并且其正常工作例如,

Validating models...

System check identified no issues (0 silenced).
June 11, 2018 - 16:57:54
Django version 2.0.4, using settings 'XApp.settings'
Starting development server at https://0:8002/
Quit the server with CTRL-BREAK.

Settings.py

INSTALLED_APPS = (...
"sslserver",
...
)

当我使用pyinstaller构建可执行文件时(我已在.spec文件中包含了包,例如Analysis(hiddenimports=[...,'sslserver',...])并与命令XApp.exe runsslserver 8000一起使用,然后它显示消息,如

Unknown command: 'runsslserver'
Type 'manage.py help' for usage.

我该如何解决?

1 个答案:

答案 0 :(得分:2)

我通过在命令字典中添加' runsslserver' sslserver' 找到了解决方案

PyInstaller\loader\rthooks\pyi_rth_django.py档案。

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 = {
         'changepassword': 'django.contrib.auth',
         'check': 'django.core',
         'clearsessions': 'django.contrib.sessions',
         'collectstatic': 'django.contrib.staticfiles',
         'compilemessages': 'django.core',
         'createcachetable': 'django.core',
         'createsuperuser': 'django.contrib.auth',
         'dbshell': 'django.core',
         'diffsettings': 'django.core',
         'dumpdata': 'django.core',
         'findstatic': 'django.contrib.staticfiles',
         'flush': 'django.core',
         'inspectdb': 'django.core',
         'loaddata': 'django.core',
         'makemessages': 'django.core',
         'makemigrations': 'django.core',
         'migrate': 'django.core',
         'runfcgi': 'django.core',
         'runserver': 'django.core',
         'runsslserver':'sslserver',
         'shell': 'django.core',
         'showmigrations': 'django.core',
         'sql': 'django.core',
         'sqlall': 'django.core',
         'sqlclear': 'django.core',
         'sqlcustom': 'django.core',
         'sqldropindexes': 'django.core',
         'sqlflush': 'django.core',
         'sqlindexes': 'django.core',
         'sqlmigrate': 'django.core',
         'sqlsequencereset': 'django.core',
         'squashmigrations': 'django.core',
         'startapp': 'django.core',
         'startproject': 'django.core',
         'syncdb': 'django.core',
         'test': 'django.core',
         'testserver': 'django.core',
         'validate': 'django.core'
    }
    return commands