首页 > 解决方案 > runsslserver 命令无法在 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.

设置.py

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

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

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

我该如何解决?

标签: pythondjangopyinstaller

解决方案


我通过在命令字典中添加'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

推荐阅读