我正在Windows 10计算机上,使用cx_Freeze和命令python setup.py bdist_msi,使用cx_Freeze将使用pygame的Python 3.7脚本冻结为exe文件(并构建.msi安装程序)。
我可以使用cx_Freeze成功构建exe,而无需指定图标,我也可以从空的python脚本构建一个exe,但使用我的app_icon.ico图标。该第二个exe确实具有图标,因此我的ico文件似乎有效。但是同时执行这两个操作(在cx_Freeze的icon=icon.ico
中添加Executable(...)
选项)将某些库复制到build \ exe.win-amd64-3.7 \文件夹后,会迅速导致以下错误:
running bdist_msi running build running build_exe creating directory build\exe.win-amd64-3.7 copying c:\users\alexandre\anaconda3\lib\site-packages\cx_Freeze\bases\Console.exe -> build\exe.win-amd64-3.7\test.exe copying c:\users\alexandre\anaconda3\api-ms-win-crt-stdio-l1-1-0.dll -> build\exe.win-amd64-3.7\api-ms-win-crt-stdio-l1-1-0.dll copying c:\users\alexandre\anaconda3\python37.dll -> build\exe.win-amd64-3.7\python37.dll copying c:\users\alexandre\anaconda3\VCRUNTIME140.dll -> build\exe.win-amd64-3.7\VCRUNTIME140.dll copying c:\users\alexandre\anaconda3\api-ms-win-crt-runtime-l1-1-0.dll -> build\exe.win-amd64-3.7\api-ms-win-crt-runtime-l1-1-0.dll copying c:\users\alexandre\anaconda3\api-ms-win-crt-math-l1-1-0.dll -> build\exe.win-amd64-3.7\api-ms-win-crt-math-l1-1-0.dll copying c:\users\alexandre\anaconda3\api-ms-win-crt-locale-l1-1-0.dll -> build\exe.win-amd64-3.7\api-ms-win-crt-locale-l1-1-0.dll copying c:\users\alexandre\anaconda3\api-ms-win-crt-string-l1-1-0.dll -> build\exe.win-amd64-3.7\api-ms-win-crt-string-l1-1-0.dll copying c:\users\alexandre\anaconda3\api-ms-win-crt-convert-l1-1-0.dll -> build\exe.win-amd64-3.7\api-ms-win-crt-convert-l1-1-0.dll copying c:\users\alexandre\anaconda3\api-ms-win-crt-time-l1-1-0.dll -> build\exe.win-amd64-3.7\api-ms-win-crt-time-l1-1-0.dll copying c:\users\alexandre\anaconda3\api-ms-win-crt-environment-l1-1-0.dll -> build\exe.win-amd64-3.7\api-ms-win-crt-environment-l1-1-0.dll copying c:\users\alexandre\anaconda3\api-ms-win-crt-heap-l1-1-0.dll -> build\exe.win-amd64-3.7\api-ms-win-crt-heap-l1-1-0.dll copying c:\users\alexandre\anaconda3\api-ms-win-crt-process-l1-1-0.dll -> build\exe.win-amd64-3.7\api-ms-win-crt-process-l1-1-0.dll copying c:\users\alexandre\anaconda3\api-ms-win-crt-conio-l1-1-0.dll -> build\exe.win-amd64-3.7\api-ms-win-crt-conio-l1-1-0.dll copying c:\users\alexandre\anaconda3\api-ms-win-crt-filesystem-l1-1-0.dll -> build\exe.win-amd64-3.7\api-ms-win-crt-filesystem-l1-1-0.dll error: [WinError 2] Le fichier spcifi est introuvable: 'build\\exe.win-amd64-3.7\\test.exe'
最后一行是法语的“找不到指定的文件:”。
这是我想出的最小示例。
我有一个Test \文件夹,其中包含一个图标app_icon.ico,一个空的test.py文件和该setup.py文件:
import cx_Freeze cx_Freeze.setup( name="Test", options={"build_exe": { "packages":["pygame"], "include_files": ["app_icon.ico"], }, }, executables = [cx_Freeze.Executable(script="test.py", #icon="app_icon.ico" ) ] )
[请注意,在使用test.py文件中的模块时尝试在setup.py中省略
"packages":["pygame"]
会导致相同的问题(我想写"packages":["pygame"]
是没有必要的,因为如果使用了cx_Freeze,它将检测到pygame)。
取消注释icon="app_icon.ico"
会导致错误,然后注释"packages":["pygame"]
将其删除。
作为最后一个令人困惑的细节:如果我选择构建自己的exe(使用游戏的原始完整python代码,但没有图标),我仍然可以为其做一个快捷方式(手动,或使用选项shortcutName = "Nurikabe", shortcutDir = "DesktopFolder"
)。它将有一个默认图标。我可以通过右键单击(在桌面快捷方式上),属性,更改图标来更改它。单击更改图标时,它将始终告诉我
找不到以下文件:%APPDATA%\ Microsoft \ Installer {一个十六进制长名称...... \ app_icon.ico
这很奇怪,因为我希望该exe在TargetDir或安装该exe的任何位置中查找其图标,但不是该%APPDATA%\ Microsoft \ Installer \文件夹。我尝试将exe文件夹安装到其他位置,但始终会出现相同的Microsoft \ Installer not found错误。即使可以,我也可以单击“确定”关闭该错误消息,然后单击“浏览”以手动查找自定义ico文件。如果最终选择了我的app_icon.ico图标,它将被接受并成为快捷方式的图标。
[结束之前,我的问题与缺少mkl_ *库无关,这是与cx_Freeze和pygame有关的SO主题中反复出现的问题。我将它们包含在我的无图标应用程序中,效果很好。我的问题确实与似乎对pygame过敏的图标有关。
我正在Windows 10计算机上,使用cx_Freeze和python setup.py bdist_msi命令,使用pygame将Python 3.7脚本冻结为exe文件(并构建.msi安装程序)。我可以...
我终于通过在"excludes"
的cx_Freeze.setup()
参数的options
键中添加模块并删除setup.py文件中不必要的mkl _ *。dll来解决该问题。 pygame和我的图标之间有干扰,而在exe中甚至没有必要!