简体   繁体   中英

System path error with PyQt and Py2exe

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.

I was desperately looking for a solution to this for the past three hours. I ended up going into the _ _ init_ _.py file in C:\\Python27\\Lib\\site-packages\\PySide directory. I changed the last line to the following:

try:
    _setupQtDirectories()
except WindowsError:
    pass

It is ugly I admit. I hope PySide people will fix this soon.

The problem was that _utils.py used __file__ , but __file__ is not available in frozen executables. This has been fixed in PySide 1.2.1 that was released a few days ago (it was fixed by commit 817a5c9bd39d3a22e2a7db9aa497059be57d58d7 ).

for PySide 1.2.1: fix get_pyside_dir() function in 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))

When using py2exe or other "freezer", the __file__ value in _utils.py will point to file inside zip archive, which is obviosly not expected by PySide. So you have to handle this case and force _utils.py to use a path, where PySide dlls & stuff are really living (in my case - a directory, where .exe file is placed).

I tried installing PySide 1.2.1 and still got this problem.

I just changed the get_pyside_dir() functions in PySide._utils to return my pyside path, which for me is "C:\\Python27\\Lib\\site-packages\\PySide"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM