10

My Problem:

I have this problem where if I try to run py2exe on my python file that uses Pyqt/Pyside I get the following error when trying to run the EXE generated in I:\Documents\Python\Buttonio_Testio\dist :

Error recieved when running Package.exe:

I:\Documents\Python\Buttonio_Testio\dist>Package.exe
Traceback (most recent call last):
  File "Package.py", line 1, in <module>
  File "PySide\__init__.pyc", line 55, in <module>
  File "PySide\__init__.pyc", line 11, in _setupQtDirectories
  File "PySide\_utils.pyc", line 87, in get_pyside_dir
  File "PySide\_utils.pyc", line 83, in _get_win32_case_sensitive_name
  File "PySide\_utils.pyc", line 58, in _get_win32_short_name
WindowsError: [Error 3] The system cannot find the path specified.

My setup.py looks like this:

    from distutils.core import setup
    import py2exe

    setup(console=['Package.py'])

My program, in Package.py looks like this:

from PySide.QtCore import *
from PySide.QtGui import *
import sys

import Gui


class Ui_Dialog(QDialog, Gui.Ui_Dialog):
    #Setupui and function afterwards generated converting XML file made by QT Desiner to python.
    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(279, 295)
        self.textBrowser = QtGui.QTextBrowser(Dialog)
        self.textBrowser.setGeometry(QtCore.QRect(10, 10, 256, 192))
        self.textBrowser.setObjectName("textBrowser")
        self.pushButton = QtGui.QPushButton(Dialog)
        self.pushButton.setGeometry(QtCore.QRect(10, 210, 251, 71))
        self.pushButton.setObjectName("PushButton")

        self.retranslateUi(Dialog)
        QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL("clicked()"), self.textBrowser.clear)
        QtCore.QMetaObject.connectSlotsByName(Dialog)

    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton.setText(QtGui.QApplication.translate("Dialog", "Clear Spam", None, QtGui.QApplication.UnicodeUTF8))

    def __init__(self, parent=None):
        super(Ui_Dialog, self).__init__(parent)
        self.setupUi(self)
        self.spam()

    def spam(self):
        self.textBrowser.append("SPAM")
        self.textBrowser.append("SPAM")
        self.textBrowser.append("SPAM")
        self.textBrowser.append("LOL")
        self.textBrowser.append("I")
        self.textBrowser.append("AM")
        self.textBrowser.append("SPAMMING")
        self.textBrowser.append("MYSELF")

app = QApplication(sys.argv)
form = Ui_Dialog()
form.show()
app.exec_()

I am running windows 8 with 32bit python and 32bit modules installed. The setup.py file was in the same folder as Package.py when I ran setup.py in Command Prompt. Besides that I don't know what other information may help fix my problem.

That's all, thank you for any answers in advance.

4

4 回答 4

7

在过去的三个小时里,我一直在拼命寻找解决方案。我最终进入了 C:\Python27\Lib\site-packages\PySide 目录中的 _ _ init_ _.py 文件。我将最后一行更改为以下内容:

try:
    _setupQtDirectories()
except WindowsError:
    pass

我承认这很丑。我希望 PySide 的人能尽快解决这个问题。

于 2013-07-11T09:38:22.870 回答
5

问题是 _utils.py used __file__,但__file__在冻结的可执行文件中不可用。这已在几天前发布的 PySide 1.2.1 中得到修复(由提交817a5c9bd39d3a22e2a7db9aa497059be57d58d7 修复)。

于 2013-08-20T23:03:01.457 回答
5

对于 PySide 1.2.1:修复get_pyside_dir()PySide/_utils.py 中的函数:

if sys.platform == 'win32':
    ...
    def get_pyside_dir():
        is_frozen = hasattr(sys, 'frozen')
        try:
            from . import QtCore
        except ImportError: 
            s1 = sys.argv[0] if is_frozen else __file__
            return _get_win32_case_sensitive_name(os.path.abspath(os.path.dirname(s1)))
        else:
            s2 = sys.argv[0] if is_frozen else QtCore.__file__
            return _get_win32_case_sensitive_name(os.path.abspath(os.path.dirname(s2)))
else:
    def get_pyside_dir():
        is_frozen = hasattr(sys, 'frozen')
        try:
            from . import QtCore
        except ImportError:
            s1 = sys.argv[0] if is_frozen else __file__
            return os.path.abspath(os.path.dirname(s1))
        else:
            s2 = sys.argv[0] if is_frozen else QtCore.__file__
            return os.path.abspath(os.path.dirname(s2))

当使用 py2exe 或其他“冷冻器”时,__file__in 中的值_utils.py将指向 zip 存档中的文件,这显然不是 PySide 所期望的。因此,您必须处理这种情况并强制_utils.py使用 PySide dll 和东西真正存在的路径(在我的情况下 - 一个目录,其中放置 .exe 文件)。

于 2014-03-19T08:04:25.300 回答
0

我尝试安装 PySide 1.2.1 仍然遇到这个问题。

我只是更改了get_pyside_dir()函数PySide._utils以返回我的 pyside 路径,对我来说是“C:\Python27\Lib\site-packages\PySide”

于 2013-08-29T02:59:26.130 回答