PySide “hello world”: py2exe/pyinstaller/cx_freeze

2019-06-07 04:48发布

I am trying to build a very basic executable (Windows) using PySide. The following script runs properly in the interpreter (Python 2.7, PySide 1.1.2)

#!/usr/bin/python

import sys

sys.stdout = open("my_stdout.log", "w")
sys.stderr = open("my_stderr.log", "w")

import PySide.QtGui
from PySide.QtGui import QApplication
from PySide.QtGui import QMessageBox


# Create the application object
app = QApplication(sys.argv)

# Create a simple dialog box
msgBox = QMessageBox()
msgBox.setText("Hello World - using PySide version " + PySide.__version__)
msgBox.exec_()

I tried 3 methods (py2exe, pyinstaller and cx_freeze) and all the 3 generated executables fail to execute. The two stdout/stderr files appear, so I found the first PySide import is making everything fail. (Unhandled exception/Access violation)

I analyzed the executable file with depends (http://www.dependencywalker.com/) and everything looks correctly linked.

Any idea?

2条回答
迷人小祖宗
2楼-- · 2019-06-07 05:22

Thank you for your help. Actually, this did not change anything :/ However, I found a solution to my problem: if I add from PySide import QtCore, QtGui, then the executable (with pyinstaller) does work!

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-06-07 05:29

You need to add the atexit module as an include. source: http://qt-project.org/wiki/Packaging_PySide_applications_on_Windows

(is also the case for Linux btw)

查看更多
登录 后发表回答