使用 pyinstaller 将 Django 移植到桌面应用程序

2024-05-26

我正在尝试将 django 项目转换为桌面应用程序。 我已经下载了 pyinstaller 的开发人员版本:github/pyinstaller/pyinstaller。

hookutils.py 修改如下:http://www.pyinstaller.org/ticket/754 http://www.pyinstaller.org/ticket/754为了让 pyinstaller 找到我的根目录:Django 根目录 c:\Workspace\mysite\mysite

我尝试编译的项目是运行后获得的初始项目:django-admin.py startproject mysite,因此尚未创建任何应用程序。

按照 pyinstaller 上所述的步骤进行操作时(http://www.pyinstaller.org/wiki/Recipe/DjangoApplication http://www.pyinstaller.org/wiki/Recipe/DjangoApplication)尝试运行服务器时出现一些错误( .\dist\mysite\mysite.exe runserver localhost:8080):

c:\Workspace\compiled>.\dist\mysite\mysite.exe runserver
Traceback (most recent call last):
  File "<string>", line 11, in <module>
  File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.core.management", line 453, in execute_from_command_line
  File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.core.management", line 392, in execute
  File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.core.management", line 263, in fetch_command
  File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.core.management", line 109, in get_commands
  File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.conf", line 53, in __getattr__
  File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.conf", line 49, in _setup
  File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.conf", line 71, in _configure_logging
  File "C:\Workspace\pyinstaller-develop\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
  File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.utils.log", line 6, in <module>
  File "C:\Workspace\pyinstaller-develop\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
  File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.views.debug", line 11, in <module>
  File "C:\Workspace\pyinstaller-develop\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
  File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.http", line 1, in <module>
  File "C:\Workspace\pyinstaller-develop\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
  File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.http.cookie", line 5, in <module>
  File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.utils.six", line 84, in __get__
  File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.utils.six", line 103, in _resolve
  File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.utils.six", line 74, in _import_module
ImportError: No module named Cookie

如果我然后在manage.py中导入Cookie,则会出现另一个错误:

Unhandled exception in thread started by <bound method Command.inner_run of <django.core.management.commands.runserver.Command object at 0x02D86CF0>>
Traceback (most recent call last):
  File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.core.management.commands.runserver", line 92, in inner_run
  File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.core.management.base", line 280, in validate
  File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.core.management.validation", line 35, in get_validation_errors
  File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.db.models.loading", line 166, in get_app_errors
  File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.db.models.loading", line 75, in _populate
  File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.db.models.loading", line 96, in load_app
  File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.utils.importlib", line 35, in import_module
  File "C:\Workspace\pyinstaller-develop\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
  File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.contrib.auth.models", line 18, in <module>
  File "C:\Workspace\pyinstaller-develop\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
  File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.contrib.auth.hashers", line 8, in <module>
  File "C:\Workspace\pyinstaller-develop\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
  File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.test", line 6, in <module>
  File "C:\Workspace\pyinstaller-develop\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
  File "c:\Workspace\compiled\build\mysite\out00-PYZ.pyz\django.test.testcases", line 35, in <module>
ImportError: cannot import name _doctest

我尝试导入 doctest,但没有帮助。

使用 python 2.7.4 和 django 1.5.1

Edit:因此,通过将 django.test 和 HTMLParser 添加到 manage.py,我让它工作:

import os
import sys
import Cookie

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "OTA.settings")

    from django.core.management import execute_from_command_line

    import django.test
    import HTMLParser
    execute_from_command_line(sys.argv)

Django 导入本地 doctest 模块。也许尝试一下import django.test?

还来自 PyInstaller 文档中有关包含附加模块的信息:

  • 您可以在 PyInstaller 命令行上提供其他文件。
  • 您可以在命令行上提供其他导入路径。
  • 您可以编辑 PyInstaller 第一次运行时写入的 myscript.spec 文件 它适合你的脚本。在规范文件中,您可以告诉 PyInstaller 有关脚本特有的代码和数据文件的信息。
  • 您可以编写“挂钩”文件来通知 PyInstaller 隐藏的导入。如果您“挂钩”其他用户也可能使用的包的导入,则可以将您的挂钩文件贡献给 PyInstaller。

如果 PyInstaller 不能满足您的需求,我还推荐 py2exe。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 pyinstaller 将 Django 移植到桌面应用程序 的相关文章

随机推荐

  • 提取数据框中值前后的 n 行

    我有一个数据框 其中包含某些值Mark柱子 我想提取n标记出现之前和之后的值 包括带有标记的行 我通过使用找到我需要的值indices lt which df Mark 1 where 1是我正在寻找的价值 现在我需要例如之前 5 行和之后
  • 使用输入按钮处理网站上的分页

    试图使用硒抓取这个网站 我的代码可以工作 但目前它只抓取第一页 该页面使用输入按钮作为浏览页面的一种方式 因此我想逐个单击每个按钮 但它不起作用 有没有人有任何其他方法来处理此类分页的导航 import requests from sele
  • Angular RouteReuseStrategy 后退按钮/跨模块

    有关我的应用程序的信息 Angular 12 由 3 个模块组成 每个模块都有一个带有列表的概述页面和一些详细信息页面 每条路线都有一个区域标签 因此我知道用户正在哪个模块中导航 所以我想实现 Angular 的 RouteReuseStr
  • JaxB2Marshaller 未将 XML 绑定到 Kotlin 数据类

    我正在编写一个批处理作业来解析 XML 提取字段并将它们保存在数据库中 解析 XML 时 它会选取 2 个根元素 但将所有字段保留为空 因此在我的数据库中 我有 2 条记录将为空字段 似乎无法弄清楚为什么它无法读取元素 TIA Bean f
  • WPF DataGrid - 将 TimeSeries 与 MultiBinding 相结合,丢失更改通知。为什么?

    我有一个具有两个 ObservableCollection 的类 其中 TimeValue 是带有更改通知的自定义日期时间 值配对 通过 INotifyPropertyChanged 我将这些称为 目标 和 实际值 当我将它们绑定到图表时
  • 如何为带有未确定的“?”的Java通用Map添加值值类型?

    我在 JDK 8 示例中看到过这种声明 Map
  • 表单未将帖子值绑定到实体

    我有一个学说实体 一个表单和 2 个字段集 当我用值填充实体时 值会按预期合并到表单中 当我尝试从表单数据创建实体时 它保持为空 我一定是忘记了什么 但就是找不到它 我还有其他几种没有字段集的表单 它们按预期工作 有任何想法吗 下面发布了我
  • 如何证明2条sql语句是等价的

    我开始用连接和子语句重写一个复杂的 SQL 语句 并获得一个看起来更简单的语句 我通过在相同的数据集上运行并获得相同的结果集来测试它 一般来说 我如何 概念上 证明这两个陈述在任何给定数据集中都是相同的 我建议学习关系代数 正如 Mchl
  • 连接池

    我有以下代码 如果我在最后使用 conn null 我仍然使用连接池吗 我知道关闭连接是一个很好的做法 但是如何处理整个连接对象呢 public void ExecuteNonQuery SqlCommand Cmd Connection
  • 涉及数学的方法给出与计算器不同的答案

    我是java新手 所以请耐心等待 我试图从比赛总数中获得胜利的百分比 但我正在做的事情还很遥远 我获取百分比的方法如下 public double winPercentage int wins int total return wins t
  • glVertexAttribDivisor 和 glVertexBindingDivisor 有什么区别?

    我一直在寻找将属性与任意顶点分组关联起来的方法 起初似乎是我实现这一目标的唯一方法 但后来我偶然发现了这个问题 https stackoverflow com questions 14169228 opengl single vertex
  • SVN:如何解决“文件已被替换”状态

    我正在修改文件 重命名它们并切换它们 我正在测试替代主页 现在我收到一条状态消息 上面写着 文件已被替换 和一个 R 我不知道该怎么做才能解决这个问题 我正在使用Coda 但它没有解决这个问题 所以我想这是命令行时间 我关心的版本是我的本地
  • 在网络上使用多种颜色的背景

    抱歉 如果标题有点误导 我想做的是用真正的浅灰色覆盖索引页面的背景 除了显示我的内容的部分 div class col sm 1 div div class col sm 8 div div class col sm 3 div 我希望 c
  • MVC3:设置下拉列表选定值

    我正在使用 mvc3 我的视图中有一个下拉列表 Html DropDownListFor m gt m State new SelectList Model StateList Value Text 有没有办法在视图中设置选定的值 扩展 R
  • 正常运行时间 iOS Objective-C - 毫秒精度

    我正在努力争取 iOS 的正常运行时间 我正在使用 mach absolute time 但我发现它在睡眠期间暂停 我找到了这个片段 time t uptime struct timeval boottime int mib 2 CTL K
  • 影响 UINavigationBar 的后退按钮方法 (iOS)

    我有一个推送到详细视图控制器的表视图 从详细视图控制器中 当我按下 后退 按钮时 我希望更改一个整数值 如何以编程方式编辑导航栏后退按钮的操作 后退按钮会自动放置在我的应用程序中 因为我使用的是表视图 所以我实际上没有创建按钮 所以我不知道
  • RowSpan 在 iTextSharp 中不起作用?

    我正在尝试将 Html 转换为 PDF 我正在使用 iTextSharp 我发现iTextSharp对CSS的支持不太好 事实上我认为 HtmlWorker 线程并不支持这一切 让我的问题更加复杂的是 iTextSharp 似乎也不支持 R
  • 只保留矩阵中某些列具有相同元素的行

    让我举个例子 假设我们有 3 个表 重点关注 N 列 Table 1 Table 2 Table 3 N Values N Values N Values 5 1 5 1 5 1 10 2 6 2 6 21 15 3 10 3 10 5 1
  • EF4 中的 Datetime2 转换

    好吧 在花了无尽的时间谷歌搜索答案之后 我必须在这个问题上添加另一个问题 我有一个包含 2 个日期时间字段的表 由 VS 2010 中的 EF4 EDMX 设计器生成 SQL 2008 中生成的字段是 datetime 而不是 dateti
  • 使用 pyinstaller 将 Django 移植到桌面应用程序

    我正在尝试将 django 项目转换为桌面应用程序 我已经下载了 pyinstaller 的开发人员版本 github pyinstaller pyinstaller hookutils py 修改如下 http www pyinstall