Use pyinstaller generate some exe files problems encountered and solutions

"Installation and use of open source image annotation tool labelme Speaking of" this blog, use pyinstaller inlet python file labelme project main.py packaged main.exe generated files can be run directly in the Windows operating system to give labelme process image annotation tool software interface, generated exe's, encountered some problems, some solved, some yet to be resolved, I hope to help a friend working in this field, but also want to familiarize yourself such questions great God who helped to solve the problem has not been resolved.

1 exe file flash back problem

The labelme run pycharm, the direct running main.py file, you can run properly, can be labelme annotation software interface, indicating that the program can run normally. Then, using pyinstall tool, use the cmd command line pyinstaller -FE: / python_workspace / labelme / main.py generate main.exe file, type the following command, you need to wait 1-2 minutes, until the emergence of Building EXE from EXE- 00.toc completed successfully appears, indicating the success of the exe file generation.

 

 

Then double-click mian.exe, the result of a cmd window appears, quickly flash back, labelme screen does not appear, cmd did not see the error message.

To see the error message, I am in cmd, cd to the directory where the main.exe, then simply type main.exe, this time main.exe will run, the following error message will be displayed.

 

 

According to the error message, you can see, the problem lies in the config / __ init__.py files, software default_config.yaml start to read the file, the file is in the config directory, after generating exe file, the software can not find the file, we went to see the __init__.py code, find the line of code is read default_config.yaml file.

config_file = osp.join(here, 'default_config.yaml')

here here is a path software runtime, os.path.join path, we can write this path absolute path, such as we directly default_config.yaml file into the directory d labelme disk, modify the code above for

#config_file = osp.join(here, 'default_config.yaml')
path = 'd:\\labelme'
config_file = osp.join(path, 'default_config.yaml')

Use pyinstaller again, generate main.exe file.

Double-click the file to run main.exe can enter labelme software interface, flash back problem is solved.

2 icon does not show a problem

There are some icons in the icon using pycharm run main.py can display icons to normal, after generating exe file, icons are not displayed properly.

main.exe operating results

 

 

The operating results in pycharm

 

 

Find information shows that the issue should be pyinstaller of converting to exe files when the picture data is lost.

The solution is to use base64 to save the icon file, so that when pyinstaller converted exe file, it will not deal with the problem picture. This way, I did not pass the practice test, it is theoretically possible, but I have not verified.

Internet also has some introductory package icon blog, modify the icon of the path, when you can pack icon pack directly into the executable file, the method does not test verification.

Question 3 Some machines can not run

Main.exe generated files and default_config.yaml files are put labelme folder, and then copied to the folder labelme d root directory, tests are run on multiple computers.

3.1 Double-click to run main.exe

都是在windows系统64位机器上测试的,有的机器能够正常运行,有的机器报错。报错信息是“此应用无法在你的电脑上运行,若要找到适用于你的电脑的版本,请咨询软件发布者。”尝试解决,在百度中查找相关报错信息,提示是兼容性问题,点击右键,选择属性,在兼容性中勾选兼容运行,依然报错。

3.2 右键以管理员身份运行

提示“windows找不到文件main.exe。请确定文件名是否正确后,再试一次。” ,在百度中查找windows找不到文件等信息,采取了一些方法,比如利用sfc /scannow命令,扫描修复系统,执行后,main.exe依然不能打开。

3.3 在命令行运行

在cmd中,cd到labelme路径下,直接键入main.exe,报错信息为16位程序不能运行,系统将main.exe看作了16位的程序,阻止了程序的运行。然后查找不支持16位应用程序的解决办法,点击开始菜单,点击运行,输入gpedit.msc。选择计算机配置,选择管理模板,点击windows组件,点击应用程序兼容性。双击防止访问16位应用程序,点击已禁止,点击确定。我使用的笔记本上面是win10系统家庭版,还不能运行gpedit.msc,还需要查找,先解决运行组策略的问题。在记事本中,输入一下内容:

 @echo off

  pushd "%~dp0"

  dir /b %systemroot%\Windows\servicing\Packages\Microsoft-Windows-GroupPolicy-ClientExtensions-Package~3*.mum >gp.txt

  dir /b  %systemroot%\servicing\Packages\Microsoft-Windows-GroupPolicy-ClientTools-Package~3*.mum >>gp.txt

  for /f %%i in ('findstr /i . gp.txt 2^>nul') do dism /online /norestart /add-package:"%systemroot%\servicing\Packages\%%i"

  pause

说明:通过dir命令遍历系统盘servicing目录,寻找组策略的配置包,找到后写入到gp.txt文件,然后通过dism命令来安装组策略包。

然后将文件另存为gpedit.bat文件,然后运行,这样就把组策略加入到系统中了。

4 结语

出现报错信息,可以采用多种方式运行程序,这样程序会呈现不一样的错误提示信息,有的错误提示信息很有用,比如闪退问题,在命令行运行,就会有一些有用的错误提示信息,最后exe不能运行的解决,也是在命令行运行,提示了16位程序的问题。通过测试不同的提示信息,找到解决方法。

Guess you like

Origin www.cnblogs.com/coodream2009/p/10983329.html