labelme_json_to_dataset报错: ModuleNotFoundError: No module named ‘labelme

目录

一、报错展示

二、解决办法

   1.已解决

   2.尝试过的解决办法【可能对其他小伙伴有用】

   (1)在安装anaconda时未添加环境变量,于是快马加鞭赶紧添加环境变量!

   (2)想过是否是labelme没有安装成功。

   (3)终于对源代码下了手!

   (4)对于转化为Json文件夹的小伙伴们,如果遇到一物多色的问题


 

一、报错展示

好家伙!一直这样循环报错

Traceback (most recent call last):
  File "D:\anaconda3\envs\py36\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "D:\anaconda3\envs\py36\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:\anaconda3\Scripts\labelme_json_to_dataset.exe\__main__.py", line 5, in <module>
ModuleNotFoundError: No module named 'labelme'

Traceback (most recent call last):
  File "D:\anaconda3\envs\py36\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "D:\anaconda3\envs\py36\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:\anaconda3\Scripts\labelme_json_to_dataset.exe\__main__.py", line 5, in <module>
ModuleNotFoundError: No module named 'labelme'

二、解决办法

    1.已解决

不得不说这个坑挖的对于我而言,心塞塞啊!!!

运行的原代码:

import os
path = 'E:\\data\\test00\\json\\'
# path是你存放json的路径
json_file = os.listdir(path)
for file in json_file:
    os.system("python D:\\anaconda3\\Scripts\\labelme_json_to_dataset.exe %s" % (path + file))    #遍历所有画好json文件,转换json文件

改过后的代码:

import os
# import json
# import labelme

path = 'E:\\data\\test01\\json_ntree\\'  # path是你存放json的路径
json_file = os.listdir(path)
for file in json_file:
    os.system("D:\\anaconda3\\Scripts\\labelme_json_to_dataset.exe %s" % (path + file))

区别:将路径上面的python去掉了,至于原因暂时我还不打算花时间现在就研究,解决了就好!能运行就很棒!

[WARNING] json_to_dataset:main:16 - This script is aimed to demonstrate how to convert the JSON file to a single image dataset.
[WARNING] json_to_dataset:main:20 - It won't handle multiple JSON files to generate a real-use dataset.
[INFO   ] json_to_dataset:main:77 - Saved to: E:\data\test01\json_ntree\10_json
[WARNING] json_to_dataset:main:16 - This script is aimed to demonstrate how to convert the JSON file to a single image dataset.
[WARNING] json_to_dataset:main:20 - It won't handle multiple JSON files to generate a real-use dataset.
[INFO   ] json_to_dataset:main:77 - Saved to: E:\data\test01\json_ntree\1007_json
[WARNING] json_to_dataset:main:16 - This script is aimed to demonstrate how to convert the JSON file to a single image dataset.
[WARNING] json_to_dataset:main:20 - It won't handle multiple JSON files to generate a real-use dataset.
[INFO   ] json_to_dataset:main:77 - Saved to: E:\data\test01\json_ntree\1008_json

 

  2.尝试过的解决办法【可能对其他小伙伴有用】

网上冲浪良久都没有发现和我这个问题一样的文章,尝试过以下方法:

(1)在安装anaconda时未添加环境变量,于是快马加鞭赶紧添加环境变量!

显然回来的时候她依旧不鸟我,照旧报她的错!【此处不展示如何添加的,如果未添加,建议查找大神的文章进行添加,那样心里舒坦些】

(2)想过是否是labelme没有安装成功。

显然不出所料的!安装成功了,报错依旧。泪奔!!!

C:\Users\jiao>pip install labelme
Requirement already satisfied: labelme in d:\anaconda3\lib\site-packages (4.5.6)
Requirement already satisfied: numpy in d:\anaconda3\lib\site-packages (from labelme) (1.16.5)
Requirement already satisfied: qtpy in d:\anaconda3\lib\site-packages (from labelme) (1.9.0)
Requirement already satisfied: imgviz>=0.11.0 in d:\anaconda3\lib\site-packages (from labelme) (1.2.3)
Requirement already satisfied: Pillow>=2.8.0 in d:\anaconda3\lib\site-packages (from labelme) (6.2.0)
Requirement already satisfied: matplotlib in d:\anaconda3\lib\site-packages (from labelme) (3.1.1)
Requirement already satisfied: termcolor in d:\anaconda3\lib\site-packages (from labelme) (1.1.0)
Requirement already satisfied: colorama in d:\anaconda3\lib\site-packages (from labelme) (0.4.1)
Requirement already satisfied: PyYAML in d:\anaconda3\lib\site-packages (from labelme) (5.1.2)
Requirement already satisfied: cycler>=0.10 in d:\anaconda3\lib\site-packages (from matplotlib->labelme) (0.10.0)
Requirement already satisfied: kiwisolver>=1.0.1 in d:\anaconda3\lib\site-packages (from matplotlib->labelme) (1.1.0)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in d:\anaconda3\lib\site-packages (from matplotlib->labelme) (2.4.2)
Requirement already satisfied: python-dateutil>=2.1 in d:\anaconda3\lib\site-packages (from matplotlib->labelme) (2.8.0)
Requirement already satisfied: six in d:\anaconda3\lib\site-packages (from cycler>=0.10->matplotlib->labelme) (1.12.0)
Requirement already satisfied: setuptools in d:\anaconda3\lib\site-packages (from kiwisolver>=1.0.1->matplotlib->labelme) (41.4.0)

(3)终于对源代码下了手!

这时候恰巧我看到了一篇文章,在这里感谢这位大神的慷慨奉献,虽然我还是依旧报错。

labelme_json_to_dataset报错: ModuleNotFoundError: No module named ‘labelme
shape.py

首先,找到shape.py文件,

其次,修改如下地方:

def polygons_to_mask(img_shape, polygons, shape_type=None):
    logger.warning(
        "The 'polygons_to_mask' function is deprecated, "
        "use 'shape_to_mask' instead."
    )
    return shape_to_mask(img_shape, points=polygons, shape_type=shape_type)
# 底下的注释便是要修改上面这行的
'''
def polygons_to_mask(img_shape, polygons):
     mask = np.zeros(img_shape[:2], dtype=np.uint8)
     mask = PIL.Image.f
     romarray(mask)
     if len(polygons)==1:
         polygons.append(polygons[0])
     xy = list(map(tuple, polygons))
     PIL.ImageDraw.Draw(mask).polygon(xy=xy, outline=1, fill=1)
     mask = np.array(mask, dtype=bool)
     return mask
'''

(4)对于转化为Json文件夹的小伙伴们,如果遇到一物多色的问题

可以参考赞!解决labelme一物多色问题【对于个人研究来说有效】这篇文章,如果你是天选之子,可能这篇文章对你有用,如果不是,那么更加恭喜你,老天还想让你再锻炼锻炼!奥利给!

 

上一篇:Centos7安装python3.6


下一篇:大神们帮我看看怎么解决