PySide 的 PyInstaller 错误
PyInstaller error with PySide
我一直在 Windows 7(64 位)上使用 PyInstaller。我目前正在使用 PyInstaller 3.1.1 和 Python 2.7.6。我创建了一个应用程序,它创建了一个简单的 PySide GUI,并使用以下命令生成了一个带有可执行文件的 dist 文件夹:
> C:\Python27\Scripts\pyinstaller.exe .\HelloWidget.spec
规范文件如下所示:
# -*- mode: python -*-
block_cipher = None
a = Analysis(['HelloWidget.py'],
pathex=['C:\Users\spearsc\Documents\python_projects\HelloWorldGui'],
binaries=None,
datas=[('.\mainwindow.ui', '.')],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
exclude_binaries=True,
name='HelloWidget',
debug=False,
strip=False,
upx=True,
console=True )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name='HelloWidget')
我想使用规范文件,因此 .ui 文件将与其他所有文件捆绑在一起。但是,当我 运行 可执行文件时,出现此错误:
> .\HelloWidget.exe
Traceback (most recent call last):
File "<string>", line 41, in <module>
File "c:\users\spearsc\appdata\local\temp\pip-build-djws3k\pyinstaller\PyInstaller\loader\pyimod03_importers.py", line
389, in load_module
File "PySide-1.2.2\PySide\__init__.py", line 55, in <module>
File "PySide-1.2.2\PySide\__init__.py", line 11, in _setupQtDirectories
File "PySide-1.2.2\PySide\_utils.py", line 87, in get_pyside_dir
File "PySide-1.2.2\PySide\_utils.py", line 83, in _get_win32_case_sensitive_name
File "PySide-1.2.2\PySide\_utils.py", line 58, in _get_win32_short_name
WindowsError: [Error 2] The system cannot find the file specified.
pyi_rth_qt4plugins returned -1
令我困惑的是,当我查看 dist 文件夹时,我看到编译的 PySide 和 Qt 文件:
Directory: C:\Users\spearsc\Documents\python_projects\HelloWorldGui\dist\HelloWidget
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 5/23/2016 4:45 PM 80896 bz2.pyd
-a--- 5/24/2016 5:20 PM 795278 HelloWidget.exe
-a--- 5/24/2016 5:20 PM 1019 HelloWidget.exe.manifest
-a--- 5/24/2016 4:42 PM 4102 mainwindow.ui
-a--- 5/24/2016 5:20 PM 1052 Microsoft.VC90.CRT.manifest
-a--- 5/23/2016 4:45 PM 245760 msvcm90.dll
-a--- 5/23/2016 4:45 PM 853328 msvcp90.dll
-a--- 5/23/2016 4:45 PM 641360 msvcr90.dll
-a--- 5/24/2016 4:43 PM 248320 pyside-python2.7.dll
-a--- 5/24/2016 4:43 PM 3063808 PySide.QtCore.pyd
-a--- 5/24/2016 4:43 PM 12750848 PySide.QtGui.pyd
-a--- 5/24/2016 4:43 PM 1095168 PySide.QtNetwork.pyd
-a--- 5/24/2016 4:43 PM 1052672 PySide.QtUiTools.pyd
-a--- 5/23/2016 4:45 PM 3004928 python27.dll
-a--- 5/24/2016 4:43 PM 3469824 QtCore4.dll
-a--- 5/24/2016 4:43 PM 11679744 QtGui4.dll
-a--- 5/24/2016 4:43 PM 1473536 QtNetwork4.dll
-a--- 5/23/2016 4:45 PM 10752 select.pyd
-a--- 5/24/2016 4:43 PM 330752 shiboken-python2.7.dll
-a--- 5/23/2016 4:45 PM 689664 unicodedata.pyd
-a--- 5/24/2016 4:43 PM 111616 _ctypes.pyd
-a--- 5/23/2016 4:45 PM 474624 _hashlib.pyd
有什么想法吗?我可以不相信我在 dist 文件夹中看到的内容吗?
5/25/16:
嗯,这很有趣。我在 _get_win32_short_name 函数中放置了一条打印语句。
def _get_win32_short_name(s):
""" Returns short name """
print s
buf_size = MAX_PATH
for i in range(2):
buf = create_unicode_buffer(u('[=14=]') * (buf_size + 1))
r = GetShortPathNameW(u(s), buf, buf_size)
if r == 0:
raise WinError()
if r < buf_size:
if PY_2:
return buf.value.encode(sys.getfilesystemencoding())
return buf.value
buf_size = r
raise WinError()
这是我在 uilt 一个新的可执行文件后得到的结果。
> .\HelloWidget.exe
C:\Users\spearsc\DOCUME~1\PYTHON~1\HELLOW~1\dist\HELLOW~1\PySide
Traceback (most recent call last):
File "<string>", line 41, in <module>
File "c:\users\spearsc\appdata\local\temp\pip-build-djws3k\pyinstaller\PyInstaller\loader\pyimod03_importers.py", line
389, in load_module
File "PySide-1.2.2\PySide\__init__.py", line 55, in <module>
File "PySide-1.2.2\PySide\__init__.py", line 11, in _setupQtDirectories
File "PySide-1.2.2\PySide\_utils.py", line 88, in get_pyside_dir
File "PySide-1.2.2\PySide\_utils.py", line 84, in _get_win32_case_sensitive_name
File "PySide-1.2.2\PySide\_utils.py", line 59, in _get_win32_short_name
WindowsError: [Error 2] The system cannot find the file specified.
pyi_rth_qt4plugins returned -1
该目录不存在。关于如何解决这个问题的任何想法?
诀窍是在 dist 文件夹中添加一个空的 PySide 文件夹。
Directory: C:\Users\spearsc\Documents\python_projects\HelloWorldGui\dist\HelloWidget
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 5/25/2016 2:46 PM PySide
-a--- 5/23/2016 4:45 PM 80896 bz2.pyd
-a--- 5/25/2016 2:46 PM 795278 HelloWidget.exe
-a--- 5/25/2016 2:46 PM 1019 HelloWidget.exe.manifest
-a--- 5/24/2016 4:42 PM 4102 mainwindow.ui
-a--- 5/25/2016 2:46 PM 1052 Microsoft.VC90.CRT.manifest
-a--- 5/23/2016 4:45 PM 245760 msvcm90.dll
-a--- 5/23/2016 4:45 PM 853328 msvcp90.dll
-a--- 5/23/2016 4:45 PM 641360 msvcr90.dll
-a--- 5/24/2016 4:43 PM 248320 pyside-python2.7.dll
-a--- 5/24/2016 4:43 PM 3063808 PySide.QtCore.pyd
-a--- 5/24/2016 4:43 PM 12750848 PySide.QtGui.pyd
-a--- 5/24/2016 4:43 PM 1095168 PySide.QtNetwork.pyd
-a--- 5/24/2016 4:43 PM 1052672 PySide.QtUiTools.pyd
-a--- 5/25/2016 2:46 PM 542208 PySide.QtXml.pyd
-a--- 5/23/2016 4:45 PM 3004928 python27.dll
-a--- 5/24/2016 4:43 PM 3469824 QtCore4.dll
-a--- 5/24/2016 4:43 PM 11679744 QtGui4.dll
-a--- 5/24/2016 4:43 PM 1473536 QtNetwork4.dll
-a--- 5/25/2016 2:46 PM 506368 QtXml4.dll
-a--- 5/23/2016 4:45 PM 10752 select.pyd
-a--- 5/24/2016 4:43 PM 330752 shiboken-python2.7.dll
-a--- 5/23/2016 4:45 PM 689664 unicodedata.pyd
-a--- 5/24/2016 4:43 PM 111616 _ctypes.pyd
-a--- 5/23/2016 4:45 PM 474624 _hashlib.pyd
在我这样做之后,我 运行 可执行文件并收到 PySide.QtXml 的导入错误,因此我生成了一个新的规范文件并对其进行了修改。
# -*- mode: python -*-
block_cipher = None
a = Analysis(['HelloWidget.py'],
pathex=['C:\Users\spearsc\Documents\python_projects\HelloWorldGui'],
binaries=None,
datas=[('.\mainwindow.ui', '.')],
hiddenimports=['PySide.QtXml'],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
exclude_binaries=True,
name='HelloWidget',
debug=False,
strip=False,
upx=True,
console=True )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name='HelloWidget')
然后我再次使用规范文件创建了可执行文件。我将空的 PySide 添加到 dist 文件夹,它起作用了!
我一直在 Windows 7(64 位)上使用 PyInstaller。我目前正在使用 PyInstaller 3.1.1 和 Python 2.7.6。我创建了一个应用程序,它创建了一个简单的 PySide GUI,并使用以下命令生成了一个带有可执行文件的 dist 文件夹:
> C:\Python27\Scripts\pyinstaller.exe .\HelloWidget.spec
规范文件如下所示:
# -*- mode: python -*-
block_cipher = None
a = Analysis(['HelloWidget.py'],
pathex=['C:\Users\spearsc\Documents\python_projects\HelloWorldGui'],
binaries=None,
datas=[('.\mainwindow.ui', '.')],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
exclude_binaries=True,
name='HelloWidget',
debug=False,
strip=False,
upx=True,
console=True )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name='HelloWidget')
我想使用规范文件,因此 .ui 文件将与其他所有文件捆绑在一起。但是,当我 运行 可执行文件时,出现此错误:
> .\HelloWidget.exe
Traceback (most recent call last):
File "<string>", line 41, in <module>
File "c:\users\spearsc\appdata\local\temp\pip-build-djws3k\pyinstaller\PyInstaller\loader\pyimod03_importers.py", line
389, in load_module
File "PySide-1.2.2\PySide\__init__.py", line 55, in <module>
File "PySide-1.2.2\PySide\__init__.py", line 11, in _setupQtDirectories
File "PySide-1.2.2\PySide\_utils.py", line 87, in get_pyside_dir
File "PySide-1.2.2\PySide\_utils.py", line 83, in _get_win32_case_sensitive_name
File "PySide-1.2.2\PySide\_utils.py", line 58, in _get_win32_short_name
WindowsError: [Error 2] The system cannot find the file specified.
pyi_rth_qt4plugins returned -1
令我困惑的是,当我查看 dist 文件夹时,我看到编译的 PySide 和 Qt 文件:
Directory: C:\Users\spearsc\Documents\python_projects\HelloWorldGui\dist\HelloWidget
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 5/23/2016 4:45 PM 80896 bz2.pyd
-a--- 5/24/2016 5:20 PM 795278 HelloWidget.exe
-a--- 5/24/2016 5:20 PM 1019 HelloWidget.exe.manifest
-a--- 5/24/2016 4:42 PM 4102 mainwindow.ui
-a--- 5/24/2016 5:20 PM 1052 Microsoft.VC90.CRT.manifest
-a--- 5/23/2016 4:45 PM 245760 msvcm90.dll
-a--- 5/23/2016 4:45 PM 853328 msvcp90.dll
-a--- 5/23/2016 4:45 PM 641360 msvcr90.dll
-a--- 5/24/2016 4:43 PM 248320 pyside-python2.7.dll
-a--- 5/24/2016 4:43 PM 3063808 PySide.QtCore.pyd
-a--- 5/24/2016 4:43 PM 12750848 PySide.QtGui.pyd
-a--- 5/24/2016 4:43 PM 1095168 PySide.QtNetwork.pyd
-a--- 5/24/2016 4:43 PM 1052672 PySide.QtUiTools.pyd
-a--- 5/23/2016 4:45 PM 3004928 python27.dll
-a--- 5/24/2016 4:43 PM 3469824 QtCore4.dll
-a--- 5/24/2016 4:43 PM 11679744 QtGui4.dll
-a--- 5/24/2016 4:43 PM 1473536 QtNetwork4.dll
-a--- 5/23/2016 4:45 PM 10752 select.pyd
-a--- 5/24/2016 4:43 PM 330752 shiboken-python2.7.dll
-a--- 5/23/2016 4:45 PM 689664 unicodedata.pyd
-a--- 5/24/2016 4:43 PM 111616 _ctypes.pyd
-a--- 5/23/2016 4:45 PM 474624 _hashlib.pyd
有什么想法吗?我可以不相信我在 dist 文件夹中看到的内容吗?
5/25/16:
嗯,这很有趣。我在 _get_win32_short_name 函数中放置了一条打印语句。
def _get_win32_short_name(s):
""" Returns short name """
print s
buf_size = MAX_PATH
for i in range(2):
buf = create_unicode_buffer(u('[=14=]') * (buf_size + 1))
r = GetShortPathNameW(u(s), buf, buf_size)
if r == 0:
raise WinError()
if r < buf_size:
if PY_2:
return buf.value.encode(sys.getfilesystemencoding())
return buf.value
buf_size = r
raise WinError()
这是我在 uilt 一个新的可执行文件后得到的结果。
> .\HelloWidget.exe
C:\Users\spearsc\DOCUME~1\PYTHON~1\HELLOW~1\dist\HELLOW~1\PySide
Traceback (most recent call last):
File "<string>", line 41, in <module>
File "c:\users\spearsc\appdata\local\temp\pip-build-djws3k\pyinstaller\PyInstaller\loader\pyimod03_importers.py", line
389, in load_module
File "PySide-1.2.2\PySide\__init__.py", line 55, in <module>
File "PySide-1.2.2\PySide\__init__.py", line 11, in _setupQtDirectories
File "PySide-1.2.2\PySide\_utils.py", line 88, in get_pyside_dir
File "PySide-1.2.2\PySide\_utils.py", line 84, in _get_win32_case_sensitive_name
File "PySide-1.2.2\PySide\_utils.py", line 59, in _get_win32_short_name
WindowsError: [Error 2] The system cannot find the file specified.
pyi_rth_qt4plugins returned -1
该目录不存在。关于如何解决这个问题的任何想法?
诀窍是在 dist 文件夹中添加一个空的 PySide 文件夹。
Directory: C:\Users\spearsc\Documents\python_projects\HelloWorldGui\dist\HelloWidget
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 5/25/2016 2:46 PM PySide
-a--- 5/23/2016 4:45 PM 80896 bz2.pyd
-a--- 5/25/2016 2:46 PM 795278 HelloWidget.exe
-a--- 5/25/2016 2:46 PM 1019 HelloWidget.exe.manifest
-a--- 5/24/2016 4:42 PM 4102 mainwindow.ui
-a--- 5/25/2016 2:46 PM 1052 Microsoft.VC90.CRT.manifest
-a--- 5/23/2016 4:45 PM 245760 msvcm90.dll
-a--- 5/23/2016 4:45 PM 853328 msvcp90.dll
-a--- 5/23/2016 4:45 PM 641360 msvcr90.dll
-a--- 5/24/2016 4:43 PM 248320 pyside-python2.7.dll
-a--- 5/24/2016 4:43 PM 3063808 PySide.QtCore.pyd
-a--- 5/24/2016 4:43 PM 12750848 PySide.QtGui.pyd
-a--- 5/24/2016 4:43 PM 1095168 PySide.QtNetwork.pyd
-a--- 5/24/2016 4:43 PM 1052672 PySide.QtUiTools.pyd
-a--- 5/25/2016 2:46 PM 542208 PySide.QtXml.pyd
-a--- 5/23/2016 4:45 PM 3004928 python27.dll
-a--- 5/24/2016 4:43 PM 3469824 QtCore4.dll
-a--- 5/24/2016 4:43 PM 11679744 QtGui4.dll
-a--- 5/24/2016 4:43 PM 1473536 QtNetwork4.dll
-a--- 5/25/2016 2:46 PM 506368 QtXml4.dll
-a--- 5/23/2016 4:45 PM 10752 select.pyd
-a--- 5/24/2016 4:43 PM 330752 shiboken-python2.7.dll
-a--- 5/23/2016 4:45 PM 689664 unicodedata.pyd
-a--- 5/24/2016 4:43 PM 111616 _ctypes.pyd
-a--- 5/23/2016 4:45 PM 474624 _hashlib.pyd
在我这样做之后,我 运行 可执行文件并收到 PySide.QtXml 的导入错误,因此我生成了一个新的规范文件并对其进行了修改。
# -*- mode: python -*-
block_cipher = None
a = Analysis(['HelloWidget.py'],
pathex=['C:\Users\spearsc\Documents\python_projects\HelloWorldGui'],
binaries=None,
datas=[('.\mainwindow.ui', '.')],
hiddenimports=['PySide.QtXml'],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
exclude_binaries=True,
name='HelloWidget',
debug=False,
strip=False,
upx=True,
console=True )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name='HelloWidget')
然后我再次使用规范文件创建了可执行文件。我将空的 PySide 添加到 dist 文件夹,它起作用了!