我修改了规范文件以包含图标,但是每次生成exe时,系统都会引发此错误:
2105 INFO: Writing RT_ICON 1 resource with 40 bytes
Traceback (most recent call last):
File "c:\program files (x86)\microsoft visual studio\shared\python36_64\lib\site-packages\win32ctypes\pywin32\pywintypes.py", line 35, in pywin32error
yield
File "c:\program files (x86)\microsoft visual studio\shared\python36_64\lib\site-packages\win32ctypes\pywin32\win32api.py", line 269, in UpdateResource
handle, type, name, language, lp_data, len(lp_data))
File "c:\program files (x86)\microsoft visual studio\shared\python36_64\lib\site-packages\win32ctypes\core\cffi\_resource.py", line 134, in _UpdateResource
function_name='UpdateResource')
File "c:\program files (x86)\microsoft visual studio\shared\python36_64\lib\site-packages\win32ctypes\core\cffi\_util.py", line 81, in __call__
self._raise_error(function_name)
File "c:\program files (x86)\microsoft visual studio\shared\python36_64\lib\site-packages\win32ctypes\core\cffi\_util.py", line 92, in _raise_error
raise exception
OSError: [WinError 87] The parameter is incorrect
我尝试使用--onefile
直接从pyinstaller以及.spec文件生成exe文件。
block_cipher =无
将ico添加到exe文件
答案 0 :(得分:0)
尝试以下代码:
from os import path
script_dir = path.dirname(path.abspath(SPEC))
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
x, y,
name='super_program',
debug=False,
strip=False,
upx=True,
runtime_tmpdir=None,
console=True,
icon=os.path.join(script_dir, 'icon.ico'))
答案 1 :(得分:0)
根据docs:
-i,--icon FILE.ico:将该图标应用于Windows 可执行文件。 FILE.exe,ID,从exe中提取具有ID的图标。 FILE.icns:将图标应用于Mac OS X上的.app捆绑包
因此您需要使用:
pyinstaller -F --icon "youricon.ico" "yourscript.py"