labelme源码运行环境配置及打包

作者:Kinglong    发表时间:2022-09-13 15:48   

关键词:labelme  Qt5  QtCore.QPoint(int   int): argument 1 has unexpected type 'float'  

labelme汉化以及打包为.exe:

https://blog.csdn.net/m0_63272812/article/details/121195125

pyinstaller打包labelme.exe:

https://blog.csdn.net/u011555629/article/details/90643417 

1.运行环境配置:

安装anaconda 下载anaconda

一直点击下一步安装

安装完成后在开始菜单找到Anaconda Prompt(anaconda3)并打开

1)创建anaconda虚拟环境labelme

conda create -n labelme python=3.9

2)激活环境

conda activate labelme

3)安装labelme所需要的依赖环境

conda install pyqt

conda install pillow

4)安装labelme

conda install labelme=3.16.2

#conda安装命令如果出错也可以使用pip命令,使用逻辑等号"==" pip install labelme==3.16.2

5)使用labelme标注图片

在刚才安装好的窗口下输入labelme,便可打开labelme

完成后,运行labelme

2.pycharm加载labelme源码

1)下载labelme源码https://github.com/wkentaro/labelme

2)解压并用以管理员身份运行pycharm打开项目

   打开后进入文件-设置 然后打开下列设置点击右上角选择Add Local Interpreter

安装以后稍等一会儿等安装环境完成

3)点击labelme文件夹下的main.py文件运行

提示No module named 'yaml',No module named 'qtpy',依次安装,如下图所示。

报错:No module named 'yaml'

pip install pyyaml

报错:No module named 'PyQt5',或报错qtpy.QtBindingsNotFoundError: No Qt bindings could be found

需要同时安装 PyQt5和pyqt5-tools

pip install PyQt5

pip install pyqt5-tools

或加速安装 pip install -i https://pypi.tuna.tsinghua.edu.cn/simple PyQt5

                  pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyqt5-tools

报错:No module named 'PIL'

pip install pillow

pip install termcolor

pip install colorama

pip install numpy

pip install imgviz

pip install natsort 

 
ModuleNotFoundError: No module named 'labelme'
PyCharm Open 打开的项目目录不对,定位到了labelme-main的父级目录。
解决方案:重新打开labelme-main即可。

3.打包 

然后对文件进行打包

pyinstaller labelme.spec

报错:

pyinstaller : The term 'pyinstaller' is not recognized as the name of a cmdlet, function,

解决方案:

1) 激活虚拟环境

conda activate labelme

2) 安装pyinstaller

pip install pyinstaller

3) 打包

pyinstaller labelme.spec

4.汉化

1)汉化方法

此时将之前下载的源码labelme目录下的translate拷贝到和exe文件的同一目录,打开就是中文了。

2)汉化失效处理

运行时正常。打包后,发现汉化失效。

是因为打包后,translate的目录获取错误。

参考:https://blog.csdn.net/sy20173081277/article/details/116541195

修改__main__.py的第164行代码,如下:

# translator.load(
#     QtCore.QLocale.system().name(),
#     osp.dirname(osp.abspath(__file__)) + "/translate",
# )
# 解决编译后的labelme.exe不加载translate中的语言文件问题
base_dir = osp.dirname(osp.abspath(__file__))
if sys.executable.find("labelme.exe") > 0:
    base_dir = os.path.dirname(os.path.realpath(sys.executable))
translator.load(
    QtCore.QLocale.system().name(),
    base_dir + "/translate",
)

5.报错处理

待解决报错:

1)QtCore.QPoint(int, int): argument 1 has unexpected type 'float'

改用QtCore.QPointF(float,float)? 

改用QtCore.QPoint(int(x),int(y))?

主要原因是PyCharm的Python环境配置到了Python3.10(有可能开始配置对的,使用过程中改到了3.10,可以在Terminal中输入python --version检查)

Apparently the QtCore API has changed in Python 3.10 and now some types are not allowed in different parts of the code. I can make a PR to add all of the int conversions and add support for Python 3.10

将python配置改为3.9,将python interpreter红框区域内配置,全部改为3.9版本的python

3)修改标注的label时,报错 index out of range

编辑标注,修改标注的label时,如果新的标注名称不在列表中,在1166行报错index out of range。app.py的1166行代码如下:

item = self.uniqLabelList.findItemsByLabel(label)[0]

在这一行添加如下代码,报错解决:

if len(self.uniqLabelList.findItemsByLabel(label)) == 0:
    item = self.uniqLabelList.createItemFromLabel(label)
    self.uniqLabelList.addItem(item)
item = self.uniqLabelList.findItemsByLabel(label)[0]

6.windows7下运行报错问题

 
1)无法启动此程序,因为计算机中丢失 api-ms-win-core-path-l1-1-0.dll
https://www.xitongzhijia.net/soft/201409.html下载压缩包(api-ms-win-core-path-l1-1-0.dll_V6.2.9200.16384_XiTongZhiJia),解压拷贝dll到C:\Windows\SysWOW64和C:\Windows\System32
 
   存在汉化失效问题。
 
 2)Failed to execute script 'pyiboot01_bootstrap' due to unhandled exception: [WinError 87] 参数错误。
缺失了win7补丁 KB2533623 导致的,其实不是 PyInstaller 的锅。
http://www.winwin7.com/soft/xtbd-29503.html#xiazai
 
3)Error loading Python DLL
是因为 Python 3.9 不再支持 win7 了,需要把 Python 版本降到 Python3.8 及以下 https://blog.csdn.net/Bit_Coders/article/details/122986216