Ubuntu20.04安装LabelImg 以及出现(ModuleNotFoundError: No module named libs.resources)错误

kaige050218 / 2024-10-06 / 原文

安装

Ubuntu系统安装labelImg:

sudo apt install pyqt5-dev-tools

接下来,通过 GitHub 下载 LabelImg:

git clone https://github.com/tzutalin/labelImg.git
cd labelimg-master
cd requirements/
sudo pip3 install -r requirements-linux-python3.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
cd ..
python3 labelImg.py

请确保在执行这些步骤之前,你的系统上已经安装了 Python 3 和 pip3

报错:

在Ubuntu系统中,运行python3 labelImg.py指令时出现(ModuleNotFoundError: No module named libs.resources)的错误,这通常意味着 Python 无法找到名为 libs.resources 的模块。

解决方法(Ubuntu20.04):

  1. 确保安装了必要的库

    • 安装 PyQt5lxml 库(如果尚未安装):

      sudo apt install python3-pyqt5
      sudo apt install python3-lxml
      
  2. 转换资源文件

    • 找到 labelImg-master 的位置,然后使用 pyrcc5 命令将 resources.qrc 转换为 resources.py

      cd path/to/labelImg-master
      pyrcc5 -o libs/resources.py resources.qrc
      

      这里 path/to/labelImg-masterlabelImg-master 文件夹的路径。

  3. 复制资源文件

    • 将生成的 resources.py 文件复制到 libs 文件夹内:

      一般情况下,resources.py已经在第2步完成之后存在于/libs文件夹中,若没有可复制到/libs文件夹中

      cp libs/resources.py path/to/labelImg-master/libs/
      
  4. 运行 LabelImg

    • 确保您在 labelImg-master 目录下,然后运行 LabelImg:

      python3 labelImg.py
      

成功安装