安装lableImg需要anaconda,这里不详细讲anaconda安装过程,我base环境下的python是3.10,后面由于这个原因造成labelImg闪退,但也有解决方法
下载labelImg
或者百度网盘:https://pan.baidu.com/s/1uQ-P3ptn4tLBwYeKHu1YQg 提取码:lntn
下载好后,win10菜单栏搜索Anaconda Prompt,打开,输入命令到下载了labelImg的路径下,
安装如下包:
pip install pyqt5
pip install lxml
执行命令
pyrcc5 -o resources.py resources.qrc
提示“pyrcc5”不被识别为内部或外部命令、可操作的程序或批处理文件
还需要安装pyqt5-tools
pip install pyqt5-tools
再次执行命令pyrcc5 -o resources.py resources.qrc,没有提示了
运行python labelImg.py 打开软件后但是会闪退,提示:TypeError: setValue(self, int): argument 1 has unexpected type ‘float‘
通过网上查找方法有如下两种解决方法:
1、labelImg需要的python版本为3.9,在Anaconda 重新建立一个新的环境重新安装
2、修改代码,这里我用的这种方法,如下:
(1)更改canvas.py,文件的路径在下载labelImg的libs文件夹中,在458行、462行、467行做出如下更改:
p.drawRect(left_top.x(), left_top.y(), rect_width), int(rect_height)改为
p.drawRect(int(left_top.x()), int(left_top.y()), int(rect_width), int(rect_height))
p.drawLine( self.prev_point.x(), 0, self.prev_point.x(), self.pixmap.height())改为
p.drawLine( int(self.prev_point.x()), 0, int(self.prev_point.x()), int(self.pixmap.height()))
p.drawLine( 0, self.prev_point.y(), self.pixmap.width(), self.prev_point.y())改为
p.drawLine( 0, int(self.prev_point.y()), int(self.pixmap.width()), int(self.prev_point.y()))
(2)更改labelImg.py文件,在883行,
bar.setValue(bar.value() + bar.singleStep() * units)改为
bar.setValue(int(bar.value() + bar.singleStep() * units))
如上便解决了闪退问题,可以使用labelImg了