python - ImportError:无法从 'is_directory' 导入名称 'PIL._util' (/usr/local/lib/python3.7/dist-packages/PIL/_util.py)

标签 python python-imaging-library importerror layout-parser

使用此代码时,我收到 Pillow 错误。我尝试重新安装枕头,但仍然遇到这个问题。有什么帮助可以让这段代码运行吗?

import layoutparser as lp
model = lp.Detectron2LayoutModel(
            config_path ='lp://PubLayNet/faster_rcnn_R_50_FPN_3x/config', # In model catalog
            label_map   ={0: "Text", 1: "Title", 2: "List", 3:"Table", 4:"Figure"}, # In model`label_map`
            extra_config=["MODEL.ROI_HEADS.SCORE_THRESH_TEST", 0.8] # Optional
        )
model.detect(image)

收到此错误:

ImportError                               Traceback (most recent call last)
[<ipython-input-6-59f0fb07b7e3>](https://localhost:8080/#) in <module>
      1 import layoutparser as lp
----> 2 model = lp.Detectron2LayoutModel(
      3             config_path ='lp://PubLayNet/faster_rcnn_R_50_FPN_3x/config', # In model catalog
      4             label_map   ={0: "Text", 1: "Title", 2: "List", 3:"Table", 4:"Figure"}, # In model`label_map`
      5             extra_config=["MODEL.ROI_HEADS.SCORE_THRESH_TEST", 0.8] # Optional

31 frames
[/usr/local/lib/python3.7/dist-packages/PIL/ImageFont.py](https://localhost:8080/#) in <module>
     35 from . import Image
     36 from ._deprecate import deprecate
---> 37 from ._util import is_directory, is_path
     38 
     39 

ImportError: cannot import name 'is_directory' from 'PIL._util' (/usr/local/lib/python3.7/dist-packages/PIL/_util.py)

最佳答案

在安装库之前运行以下命令:

!pip install fastcore -U

关于python - ImportError:无法从 'is_directory' 导入名称 'PIL._util' (/usr/local/lib/python3.7/dist-packages/PIL/_util.py),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73711994/

相关文章:

python - Sphinx : Import error in not to document package. 有没有办法到 "skip"?

python - Flask foreign_keys 仍然显示 AmbiguousForeignKeysError

python - 从 QVBoxLayout 中删除自定义小部件

python - 成对相似性

python - 在numpy矩阵中查找最大列值的行索引

python - 矢量图像的图像比较(基于边缘检测)?

Python PIL.ExifTags - 不确定它是什么

python - 支持一个python包的两个版本,无需客户端更改代码

python - 如何最大限度地减少运行时间 : Value Replacement Iterations in Pandas

python - "ImportError: Failed to load GLFW3 shared library"在 Linux 上没有 root 访问权限