简体   繁体   English

Django 4.0 pyinstaller 5.1 未能运行 runserver 命令引发错误

[英]Django 4.0 pyinstaller 5.1 failed to run runserver command throws an error

Trying to package a django 4.0 project to exe using pyinstaller 5.1 and python 3.9 and it was successfully but i ran into a problem that when i run it in cmd with./manage.exe runserver i get this error Trying to package a django 4.0 project to exe using pyinstaller 5.1 and python 3.9 and it was successfully but i ran into a problem that when i run it in cmd with./manage.exe runserver i get this error

Am currently working in a virtual environment and am using windows 10 operating system The project is a basic test project were am using a single app, a few satic files and sqlite 3 as my default database我目前在虚拟环境中工作,并且正在使用 windows 10 操作系统该项目是一个基本的测试项目,正在使用单个应用程序、一些 satic 文件和 sqlite 3 作为我的默认数据库

PyInstaller\hooks\rthooks\pyi_rth_django.py", line 69, in _restart_with_reloader
return _old_restart_with_reloader(*args)
File "django\utils\autoreload.py", line 263, in restart_with_reloader
args = get_child_arguments()
File "django\utils\autoreload.py", line 250, in get_child_arguments
raise RuntimeError('Script %s does not exist.' % py_script)
RuntimeError: Script runserver does not exist.
[7892] Failed to execute script 'manage' due to unhandled exception!

This is my.spec file这是 my.spec 文件

# -*- mode: python ; coding: utf-8 -*-


block_cipher = None

a = Analysis(
    ['manage.py'],
    pathex=[],
    binaries=[],
    datas=[],
    hiddenimports=[
    'webapp.urls',
    'webapp.apps'
    ],
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[],
    win_no_prefer_redirects=False,
    win_private_assemblies=False,
    cipher=block_cipher,
    noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)

exe = EXE(
    pyz,
    a.scripts,
    [],
    exclude_binaries=True,
    name='manage',
    debug=False,
    bootloader_ignore_signals=False,
    strip=False,
    upx=True,
    console=True,
    disable_windowed_traceback=False,
    argv_emulation=False,
    target_arch=None,
    codesign_identity=None,
    entitlements_file=None,
)
coll = COLLECT(
    exe,
    a.binaries,
    a.zipfiles,
    a.datas,
    strip=False,
    upx=True,
    upx_exclude=[],
    name='manage',
)

This is urls.py这是 urls.py

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('', include('webapp.urls')),
    path('admin/', admin.site.urls),
]

manage.py管理.py

#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
    """Run administrative tasks."""
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'muviny.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
            raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
            ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()

Just found the answer: since pyinstaller doesn't support reload, i had to disable the releod function while running the server ./manage.exe runserver --noreload刚刚找到答案:由于pyinstaller不支持重新加载,我不得不在运行服务器时禁用releod function ./manage.exe runserver --noreload

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM