python-pillow / Pillow

Python Imaging Library (Fork)
https://python-pillow.org
Other
11.8k stars 2.13k forks source link

ImportError #8049

Closed itsvijaychoudhary closed 3 weeks ago

itsvijaychoudhary commented 3 weeks ago

What did you do?

I have just append the images in face recognition project

What did you expect to happen?

I want to print the total number of images

What actually happened?

I got an ImportError

What are your OS, Python and Pillow versions?

/usr/local/bin/python3.10 /Users/vijaychoudhary/Desktop/face reco/EncodeGenerator.py 
Traceback (most recent call last):
  File "/Users/vijaychoudhary/Desktop/face reco/EncodeGenerator.py", line 2, in <module>
    import face_recognition
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/face_recognition/__init__.py", line 7, in <module>
    from .api import load_image_file, face_locations, batch_face_locations, face_landmarks, face_encodings, compare_faces, face_distance
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/face_recognition/api.py", line 4, in <module>
    import dlib
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/dlib/__init__.py", line 19, in <module>
    from _dlib_pybind11 import *
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/_dlib_pybind11.cpython-310-darwin.so, 0x0002): Library not loaded: /opt/homebrew/opt/mbedtls/lib/libmbedcrypto.14.dylib
  Referenced from: <8C2E2CF9-054E-300F-BDE7-3DE52F848638> /opt/homebrew/Cellar/librist/0.2.7_3/lib/librist.4.dylib
  Reason: tried: '/opt/homebrew/opt/mbedtls/lib/libmbedcrypto.14.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/opt/mbedtls/lib/libmbedcrypto.14.dylib' (no such file), '/opt/homebrew/opt/mbedtls/lib/libmbedcrypto.14.dylib' (no such file), '/usr/lib/libmbedcrypto.14.dylib' (no such file, not in dyld cache), '/opt/homebrew/Cellar/mbedtls/3.5.1/lib/libmbedcrypto.14.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/Cellar/mbedtls/3.5.1/lib/libmbedcrypto.14.dylib' (no such file), '/opt/homebrew/Cellar/mbedtls/3.5.1/lib/libmbedcrypto.14.dylib' (no such file), '/usr/lib/libmbedcrypto.14.dylib' (no such file, not in dyld cache)

Process finished with exit code 1
import cv2
import face_recognition
import pickle
import os
from PIL import Image

# importing the student images

folderPath = 'Images'
modePathList = os.listdir(folderPath)
imgList = []
for path in modePathList:
    imgList.append(cv2.imread(os.path.join(folderPath, path)))
print(len(imgList))
radarhere commented 3 weeks ago

You're importing Pillow in your code, but you're not using it. So if your goal is to just run the code you've posted, and you believe Pillow is in your way, then you can stop importing Pillow.

import cv2
import face_recognition
import pickle
import os

# importing the student images

folderPath = 'Images'
modePathList = os.listdir(folderPath)
imgList = []
for path in modePathList:
    imgList.append(cv2.imread(os.path.join(folderPath, path)))
print(len(imgList))

However, Iooking at your error, I don't think Pillow is the cause of your problem. I think face_recognition is. I would suggest

import cv2
import os

# importing the student images

folderPath = 'Images'
modePathList = os.listdir(folderPath)
imgList = []
for path in modePathList:
    imgList.append(cv2.imread(os.path.join(folderPath, path)))
print(len(imgList))
radarhere commented 3 weeks ago

If that does solve your problem, but you would still like to use face_recognition, that isn't a Pillow problem, so I would suggest that this is a matter for https://github.com/ageitgey/face_recognition or https://stackoverflow.com/.

To be helpful though, https://github.com/Homebrew/homebrew-core/issues/153177 suggests that running brew reinstall librist might fix your issue.

itsvijaychoudhary commented 3 weeks ago

thank you it worked for me. I just need to import cv2 and os

itsvijaychoudhary commented 3 weeks ago

but I'm still getting the same error when i'm using face_recognition library and now i'm using it in the code. how do i solve that?

radarhere commented 3 weeks ago

https://github.com/Homebrew/homebrew-core/issues/153177 suggests that running brew reinstall librist might fix your issue.

However, that isn't a Pillow problem. This might be a matter for https://github.com/ageitgey/face_recognition or https://stackoverflow.com/ instead.

itsvijaychoudhary commented 3 weeks ago

i run brew reinstall librist and after that i run the same program in pycharm and got this error.

Traceback (most recent call last):
  File "/Users/vijaychoudhary/Desktop/face reco/EncodeGenerator.py", line 2, in <module>
    import face_recognition
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/face_recognition/__init__.py", line 7, in <module>
    from .api import load_image_file, face_locations, batch_face_locations, face_landmarks, face_encodings, compare_faces, face_distance
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/face_recognition/api.py", line 4, in <module>
    import dlib
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/dlib/__init__.py", line 19, in <module>
    from _dlib_pybind11 import *
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/_dlib_pybind11.cpython-310-darwin.so, 0x0002): Library not loaded: /opt/homebrew/opt/ffmpeg/lib/libavdevice.60.dylib
  Referenced from: <2D7DF8F2-EE4E-333E-B755-5CCB2B984C06> /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/_dlib_pybind11.cpython-310-darwin.so
  Reason: tried: '/opt/homebrew/opt/ffmpeg/lib/libavdevice.60.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/opt/ffmpeg/lib/libavdevice.60.dylib' (no such file), '/opt/homebrew/opt/ffmpeg/lib/libavdevice.60.dylib' (no such file), '/opt/homebrew/Cellar/ffmpeg/7.0_1/lib/libavdevice.60.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/Cellar/ffmpeg/7.0_1/lib/libavdevice.60.dylib' (no such file), '/opt/homebrew/Cellar/ffmpeg/7.0_1/lib/libavdevice.60.dylib' (no such file)

Process finished with exit code 1
radarhere commented 2 weeks ago

Again, the problem you're describing is not a Pillow one, so there are other places that would be more helpful to you.

https://github.com/ageitgey/face_recognition/issues/1534 and https://github.com/ageitgey/face_recognition/issues/1536 are face_recognition users asking very similar questions. You might want to ask if they ever found a solution.