无法在pyinstaller中导入文件本身

问题描述

我正在尝试使用pyinstaller打包我的单个文件Web应用程序,如下所示,该应用程序可以通过测试正常运行,希望在没有python的另一台计算机上使用它

import os

this = os.path.splitext(os.path.basename(__file__))[0]

if __name__ == '__main__':
    import sys
    from daphne.cli import CommandLineInterface

    sys.exit(CommandLineInterface().run(["-p","30003",this + ":application"]))
else:
    import django
    from django.conf import settings
    from django.core.asgi import get_asgi_application
    from django.urls import re_path
    from django.http import JsonResponse

    DEBUG = True
    urlpatterns = [
        re_path(r'^',lambda x: JsonResponse({'msg': 'success'}))
    ]

    SETTINGS = dict(
        DEBUG=DEBUG,ROOT_URLconf=this
    )
    settings.configure(**SETTINGS)
    django.setup()
    application = get_asgi_application()

但是当我运行打包文件时,它返回错误

daphne/server.py:11: UserWarning: Something has already installed a non-asyncio Twisted reactor. Attempting to uninstall it; you can fix this warning by importing daphne.server early in your codebase or finding the package that imports Twisted and importing it later on.
Traceback (most recent call last):
  File "single.py",line 9,in <module>
  File "daphne/cli.py",line 252,in run
  File "daphne/utils.py",line 12,in import_by_path
  File "importlib/__init__.py",line 127,in import_module
  File "<frozen importlib._bootstrap>",line 1014,in _gcd_import
  File "<frozen importlib._bootstrap>",line 991,in _find_and_load
  File "<frozen importlib._bootstrap>",line 973,in _find_and_load_unlocked
ModuleNotFoundError: No module named 'single'
[596096] Failed to execute script single

似乎有两个问题,daphne的导入运行两次,无法找到作为应用程序的自我导入 我该怎么解决

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)