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 #8049

Closed
itsvijaychoudhary opened this issue May 10, 2024 · 7 comments
Closed

ImportError #8049

itsvijaychoudhary opened this issue May 10, 2024 · 7 comments

Comments

@itsvijaychoudhary
Copy link

itsvijaychoudhary commented May 10, 2024

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?

  • OS: MacOS M1 Sonoma 14.3
  • Python: 3.11.4
  • Pillow: 9.0.0
/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
Copy link
Member

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
Copy link
Member

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, Homebrew/homebrew-core#153177 suggests that running brew reinstall librist might fix your issue.

@radarhere radarhere changed the title importerror ImportError May 11, 2024
@itsvijaychoudhary
Copy link
Author

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

@itsvijaychoudhary
Copy link
Author

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
Copy link
Member

radarhere commented May 11, 2024

Homebrew/homebrew-core#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.

@nulano nulano added the Invalid label May 11, 2024
@itsvijaychoudhary
Copy link
Author

itsvijaychoudhary commented May 11, 2024

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
Copy link
Member

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

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

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

No branches or pull requests

3 participants