【问题标题】:What is the best approach with compiling PySide application编译 PySide 应用程序的最佳方法是什么
【发布时间】:2013-08-23 08:14:18
【问题描述】:

在为 Linux 编译 pyside 代码时,我感到很痛苦……对于 Windows,我的源代码大约 300kb。我想知道什么是最安全的编译方式。

  1. 编译 Qt、PySide 绑定、Python 2.7 以及每次导入都使用单独的进程是最好的吗?

1.1。如果我这样做,是否更容易跟踪错误?

  1. 编译时qt4-qmake有什么理由使用它吗?

  2. 为 PyQt 而不是 Pyside 重写代码会更好吗?

  3. 是否取决于某些版本的快乐组合,例如:(Qt v4.8.2,pyside 1.0.1,python 2.7.3)?

编辑: 通过编译意味着将 Python 脚本转换为可执行的 Windows/Linux 程序,就像 py2exe、cx_Freeze 或 PyInstaller 所做的那样。

感谢您的建议。

【问题讨论】:

  • 我不明白你的问题:1.- 你想构建 PySide 吗? -> 使用 Nicola 的答案(顺便说一句,在 Linux 上编译它比在 Windows 上容易得多) 2.- 使用 Pyside 编译一个应用程序? -> 嗯,那是 python 代码,它不能编译... 3.- 在 C++ 应用程序中使用 Python 代码? -> docs.python.org/2/extending/embedding.html
  • Pythonist 可以理解我...请参阅:stackoverflow.com/questions/1689086/…
  • 哦!你想制作一个独立的可执行文件吗?好吧,你不需要编译任何东西(至少,使用 cx_freeze)。只需安装 cx_freeze(或 py2exe 等),创建 setup.py 文件,运行它(setup.py 文件),然后开心就好:) 但是,跟踪错误很难看到(在 Windows 中)。

标签: python qt cross-compiling pyside


【解决方案1】:

我唯一的经验是使用 cx_freeze(使用 python 3.3)。它适用于 Windows/Linux/OSX。 可以在此处找到一个简单的示例(及其文档):http://cx-freeze.readthedocs.org/en/latest/distutils.html#distutils

另一个例子:

from cx_Freeze import setup, Executable

# dependencies
build_exe_options = {
    "packages": ["os", "sys", "glob", "simplejson", "re", "atexit", "PySide.QtCore", "PySide.QtGui", "PySide.QtXml"],
    "include_files": [("./example/Ui/MainWindow.ui", "Ui/MainWindow.ui"),
                      ("./example/Ui/ExampleWidget.ui", "Ui/ExampleWidget.ui"),
                      ("./example/Ui/TestDialog.ui", "Ui/TestDialog.ui"),
                      ("./example/Resources/style.qss", "Ui/style.qss")], # this isn't necessary after all
    "excludes": ["Tkinter", "Tkconstants", "tcl"],
    "build_exe": "build",
    "icon": "./example/Resources/Icons/monitor.ico"
}

executable = [
    Executable("./bin/Example.py",
               base="Win32GUI",
               targetName="Example.exe",
               targetDir="build",
               copyDependentFiles=True)
]

setup(
    name="Example",
    version="0.1",
    description="Example", # Using the word "test" makes the exe to invoke the UAC in win7. WTH?
    author="Me",
    options={"build_exe": build_exe_options},
    executables=executable,
    requires=['PySide', 'cx_Freeze', 'simplejson']
)

【讨论】:

  • 感谢您的建议、链接和示例。这正是我所需要的。
【解决方案2】:

按照PySide page on PyPI 上的说明进行操作。

【讨论】:

  • 但它是关于编译 PySide,而不是使用 Pyside 的应用程序!?
  • 鉴于没有适用于 Linux 的二进制官方发行版,这已在我链接的页面中进行了解释。
  • 嗯,Windows编译最重要。
  • 您是否尝试交叉编译到不同的平台?也许嵌入?否则 PyPI 页面还解释了如何为 Windows 构建。也许你应该重新提出你的问题。
猜你喜欢
  • 1970-01-01
  • 2011-12-24
  • 1970-01-01
  • 2010-09-23
  • 2010-09-18
  • 2020-01-05
  • 2011-06-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多