我一直在Windows 7 (64位)上玩PyInstaller。我目前在Python2.7.6中使用PyInstaller 3.1.1。我创建了一个应用程序,该应用程序创建了一个简单的PySide图形用户界面,并使用以下命令生成了一个带有可执行文件的dist文件夹:
> C:\Python27\Scripts\pyinstaller.exe .\HelloWidget.spec这就是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函数中放置了一个print语句。
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('\0') * (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()这是我在构建了一个新的可执行文件之后得到的结果。
> .\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目录不存在。有什么解决办法吗?
发布于 2016-05-25 21:53:33
诀窍是在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')然后,我再次使用spec文件创建可执行文件。我将空的PySide添加到dist文件夹中,它成功了!
https://stackoverflow.com/questions/37426080
复制相似问题