face_recognition
face_recognition copied to clipboard
module 'face_recognition' has no attribute 'load_image_file'
- face_recognition version: latest
- Python version: 3
- Operating System: raspberry pi
Description
Installed dlib using: https://gist.github.com/ageitgey/629d75c1baac34dfa5ca2a1928a7aeaf and pip3 install face_recognition
. Cloned the samples repo.
What I Did
pi@raspberrypi:~ $ source ~/.profile
pi@raspberrypi:~ $ workon cv
(cv) pi@raspberrypi:~ $ python facerec.py
Traceback (most recent call last):
File "facerec.py", line 17, in <module>
obama_image = face_recognition.load_image_file("obama.jpg")
AttributeError: module 'face_recognition' has no attribute 'load_image_file'
(cv) pi@raspberrypi:~ $
Do you have another file in that folder called face_recognition.py
maybe?
This same error plagues my face rec script on my pi.
No face_recognition.py
file in the folder. I've cloned the examples folder from this repo.
Same problem for me, did you solve it ?
@marksrg no we have not resolved this issue yet
If you don't have a file called face_recognition.py
, most likely you have a weird mismash of python versions installed and something has gone wrong. This seems to happen with Anaconda for whatever reason.
If you are having this issue, please save this script to a file and run it with the same version of python you are having the issue with. Then paste the full output from the script in a comment here and we'll see if we can figure it out.
import sys
import inspect
import face_recognition
try:
print("face_recognition version:")
print(face_recognition.__version__)
except Exception as e:
print(e)
try:
print()
print("face_recognition path:")
print(face_recognition.__file__)
except Exception as e:
print(e)
try:
print()
print("face_recognition path (alternate method):")
print(inspect.getfile(face_recognition))
except Exception as e:
print(e)
print()
print("Python version:")
print(sys.version)
print("Python executable:")
print(sys.executable)
try:
print("Python base path:")
print(sys.base_prefix)
except Exception as e:
print(e)
print("Python base path (exec):")
print(sys.exec_prefix)
print("Python system path:")
print(sys.path)
Hey ! Thanks for your help, I really appreciate that since I don't really understand how Python works with the OS.
Here is the result of your function :
face_recognition version: module 'face_recognition' has no attribute 'version'
face_recognition path: module 'face_recognition' has no attribute 'file'
face_recognition path (alternate method): <module 'face_recognition' (namespace)> is a built-in module
Python version: 3.5.3 (default, Jan 19 2017, 14:11:04) [GCC 6.3.0 20170124] Python executable: /home/pi/.virtualenvs/cv/bin/python3 Python base path: /home/pi/.virtualenvs/cv Python base path (exec): /home/pi/.virtualenvs/cv Python system path: ['/home/pi', '/home/pi', '/home/pi/face_recognition/face_recognition', '/home/pi/dlib', '/home/pi/.virtualenvs/cv/lib/python35.zip', '/home/pi/.virtualenvs/cv/lib/python3.5', '/home/pi/.virtualenvs/cv/lib/python3.5/plat-arm-linux-gnueabihf', '/home/pi/.virtualenvs/cv/lib/python3.5/lib-dynload', '/usr/lib/python3.5', '/usr/lib/python3.5/plat-arm-linux-gnueabihf', '/home/pi/.virtualenvs/cv/lib/python3.5/site-packages']
The '/home/pi/face_recognition/face_recognition'
in the system path is suspicious. Did you set the PYTHONPATH variable yourself or do you know where that got set? I'm not sure how that happened.
As a test, I would try moving the '/home/pi/face_recognition/
folder to a different folder name and seeing if you get the same problem. I'm guessing that folder is getting picked up instead of the real installed copy.
It's a strange problem and it's hard to debug without being able to reproduce the problem myself so far, so this is kind of a guess. Let me know what result you get.
Yes I set the PYTHONPATH myself otherwise Python 3 from the cv virtual environnement wouldn't find face_recognition. I changed the name to '/home/pi/face_recognition_lib/face_recognition' but now that I have deleted the PYTHONPATH the module isn't found.
I understand, no problem ! It's already very nice from you to help me since I'm a beginner.
We get the following output from the script
face_recognition version:
0.1.0
face_recognition path:
/usr/local/lib/python3.5/dist-packages/face_recognition/__init__.py
face_recognition path (alternate method):
/usr/local/lib/python3.5/dist-packages/face_recognition/__init__.py
Python version:
3.5.3 (default, Jan 19 2017, 14:11:04)
[GCC 6.3.0 20170124]
Python executable:
/usr/bin/python3
Python base path:
/usr
Python base path (exec):
/usr
Python system path:
['/home/pi/faces', '/usr/lib/python3/dist-packages/thonny/shared', '/usr/lib/python35.zip', '/usr/lib/python3.5', '/usr/lib/python3.5/plat-arm-linux-gnueabihf', '/usr/lib/python3.5/lib-dynload', '/home/pi/.local/lib/python3.5/site-packages', '/usr/local/lib/python3.5/dist-packages', '/usr/local/lib/python3.5/dist-packages/face_recognition-1.2.1-py3.5.egg', '/usr/lib/python3/dist-packages', '/home/pi/.thonny/jedi_0.10.2']
@mvput Hmm. It's loading the module from /usr/local/lib/python3.5/dist-packages/face_recognition/__init__.py
but you also have /usr/local/lib/python3.5/dist-packages/face_recognition-1.2.1-py3.5.egg
in your path. That makes it seem like you have two copies installed somehow.
You might try deleting the /usr/local/lib/python3.5/dist-packages/face_recognition/
folder and seeing it the copy from the egg then loads correctly. Just a guess!
@marksrg Now that you got rid of that extra copy, you might try just installing face_recognition from pip again - pip3 install face_recognition
and seeing if it works after that.
Thank you for your help ! Actually I copied the face_recognition folder to one of the folders in the PYTHONPATH and it works well.
Great!
We deleted the /usr/local/lib/python3.5/dist-packages/face_recognition/
folder
And that worked! The screen camera screen window came up only the image starts flickering and 25% cpuload we will investigate that further
Thank you for your help in advance
Meet same iusse, resolved. THX
Hello! I got the following output from the script, and I don't understand...
face_recognition version: module 'face_recognition' has no attribute 'version'
face_recognition path: C:\pycharm\untitled1\face_recognition.py
face_recognition path (alternate method): C:\pycharm\untitled1\face_recognition.py
Python version: 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 bit (AMD64)] Python executable: C:\Users\ASUS\venv\untitled1\Scripts\python.exe Python base path: C:\Users\ASUS\venv\untitled1 Python base path (exec): C:\Users\ASUS\venv\untitled1 Python system path: ['C:\pycharm\untitled1', 'C:\pycharm\untitled1', 'C:\Users\ASUS\venv\untitled1\Scripts\python36.zip', 'C:\Users\ASUS\venv\untitled1\DLLs', 'C:\Users\ASUS\venv\untitled1\lib', 'C:\Users\ASUS\venv\untitled1\Scripts', 'C:\Users\ASUS\AppData\Local\Programs\Python\Python36\Lib', 'C:\Users\ASUS\AppData\Local\Programs\Python\Python36\DLLs', 'C:\Users\ASUS\venv\untitled1', 'C:\Users\ASUS\venv\untitled1\lib\site-packages', 'C:\Program Files\JetBrains\PyCharm 2018.1.4\helpers\pycharm_matplotlib_backend']
Oh! I know how to solve such mistakes. Thank you anyway!
Don't name your own script face_recogntion.py
because then you are just importing your own script in itself instead of importing the library :)
Hello i'm the same error, somebody help me
`C:\Users\Fabiano Oliveira\Desktop\Nova pasta>python teste.py face_recognition version: module 'face_recognition' has no attribute 'version'
face_recognition path: None
face_recognition path (alternate method): <module 'face_recognition' (namespace)> is a built-in module
Python version: 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit (Intel)] Python executable: C:\Users\Fabiano Oliveira\AppData\Local\Programs\Python\Python37-32\python.exe Python base path: C:\Users\Fabiano Oliveira\AppData\Local\Programs\Python\Python37-32 Python base path (exec): C:\Users\Fabiano Oliveira\AppData\Local\Programs\Python\Python37-32 Python system path: ['C:\Users\Fabiano Oliveira\Desktop\Nova pasta', 'C:\Users\Fabiano Oliveira\AppData\Local\Programs\Python\Python37-32\python37.zip', 'C:\Users\Fabiano Oliveira\AppData\Local\Programs\Python\Python37-32\DLLs', 'C:\Users\Fabiano Oliveira\AppData\Local\Programs\Python\Python37-32\lib', 'C:\Users\Fabiano Oliveira\AppData\Local\Programs\Python\Python37-32', 'C:\Users\Fabiano Oliveira\AppData\Roaming\Python\Python37\site-packages', 'C:\Users\Fabiano Oliveira\AppData\Local\Programs\Python\Python37-32\lib\site-packages']`
face_recognition version: 0.1.0
face_recognition path: /anaconda3/lib/python3.6/site-packages/face_recognition_models/init.py
face_recognition path (alternate method): /anaconda3/lib/python3.6/site-packages/face_recognition_models/init.py
Python version: 3.6.2 |Continuum Analytics, Inc.| (default, Jul 20 2017, 13:14:59) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] Python executable: /anaconda3/bin/python Python base path: /anaconda3 Python base path (exec): /anaconda3 Python system path: ['', '/anaconda3/lib/python36.zip', '/anaconda3/lib/python3.6', '/anaconda3/lib/python3.6/lib-dynload', '/anaconda3/lib/python3.6/site-packages', '/anaconda3/lib/python3.6/site-packages/aeosa', '/anaconda3/lib/python3.6/site-packages/dlib-19.16.99-py3.6-macosx-10.7-x86_64.egg', '/anaconda3/lib/python3.6/site-packages/IPython/extensions', '/Users/monica/.ipython']
I am getting this, can anyone help ?
@Monica1998 it looks like somehow you got the face_recognition_models package installed where face_recognition should be. How did you install things?
I installed it through conda, how can i repair this. I am using anaconda
through this website : https://anaconda.org/akode/face_recognition_models
@Monica1998 Did you found any solution to the problem. I'm also using conda and imported the same package.
Thanks. I have a function which is named "face_recognition". After I modify it, it works.
Importing the module as face_recognition will not work
I assume you have installed from the github source and not from pip
so instead import as import face_recognition.face_recognition.api as face_recognition
because this is how the directory is structured.
also keep the face_recognition source in the same folder as your python is being run.
Worked for me
@mvput This is how i get when i ran your script face_recognition version: 0.1.0
face_recognition path: C:\Users\manoj\Anaconda3\lib\site-packages\face_recognition_models_init_.py
face_recognition path (alternate method): C:\Users\manoj\Anaconda3\lib\site-packages\face_recognition_models_init_.py
Python version: 3.7.4 (default, Aug 9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)] Python executable: C:\Users\manoj\Anaconda3\python.exe Python base path: C:\Users\manoj\Anaconda3 Python base path (exec): C:\Users\manoj\Anaconda3 Python system path: ['C:\Users\manoj', 'C:\Users\manoj\Anaconda3\python37.zip', 'C:\Users\manoj\Anaconda3\DLLs', 'C:\Users\manoj\Anaconda3\lib', 'C:\Users\manoj\Anaconda3', '', 'C:\Users\manoj\AppData\Roaming\Python\Python37\site-packages', 'C:\Users\manoj\Anaconda3\lib\site-packages', 'C:\Users\manoj\Anaconda3\lib\site-packages\win32', 'C:\Users\manoj\Anaconda3\lib\site-packages\win32\lib', 'C:\Users\manoj\Anaconda3\lib\site-packages\Pythonwin', 'C:\Users\manoj\Anaconda3\lib\site-packages\IPython\extensions', 'C:\Users\manoj\.ipython'] i got this error after importing the face_recognition_models in my anaconda prompt
import face_recognition_models as face_recognition import dlib image = face_recognition.load_image_file("V2_Image100.jpg") face_locations = face_recognition.face_locations(image)
import face_recognition_models as face_recognition import dlib image = face_recognition.load_image_file("V2_Image100.jpg") face_locations = face_recognition.face_locations(image)
AttributeError Traceback (most recent call last)
AttributeError: module 'face_recognition_models' has no attribute 'load_image_file'
I rename my file from Face_Recognition.py to something else and it works.
I rename my file from Face_Recognition.py to something else and it works.
yaaa same happened with me when i got Attribute Error: for Load_image_file. It worked when i changed the file name. Im a beginner too 👍