PySide “hello world”: py2exe/pyinstaller/cx_freeze and access violation

允我心安 提交于 2019-12-23 03:53:07

问题


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?


回答1:


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)




回答2:


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!



来源:https://stackoverflow.com/questions/12386263/pyside-hello-world-py2exe-pyinstaller-cx-freeze-and-access-violation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!