Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
arhamshah opened this issue Sep 14, 2022 · 4 comments

Comments

@arhamshah
Copy link

While using this code, I get this error of Pillow. I tried re-installing pillow but still struggling with this issue. Any help to make this code run?

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)

Getting this error:

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)

@MarouaneZ1
Copy link

i got the same problem while using Detectron2LayoutModel on google collab, did you fix it yet ?

@arhamshah
Copy link
Author

arhamshah commented Sep 26, 2022

I solved by uninstalling the latest pillow version and instead installed pillow of version 7.1.2
!pip install pillow==7.1.2

@MarouaneZ1
Copy link

I solved by uninstalling the latest pillow version and instead installed pillow of version 7.1.2 !pip install pillow==7.1.2

i just did what you told me and it worked thank you very much brother

@NUSTHR
Copy link

NUSTHR commented Mar 27, 2024

It works. Thank you a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants