face_recognition icon indicating copy to clipboard operation
face_recognition copied to clipboard

module 'face_recognition' has no attribute 'load_image_file'

Open mvput opened this issue 7 years ago • 36 comments

  • 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:~ $

mvput avatar Jan 22 '18 12:01 mvput

Do you have another file in that folder called face_recognition.py maybe?

ageitgey avatar Jan 26 '18 16:01 ageitgey

This same error plagues my face rec script on my pi.

netrosec avatar Jan 27 '18 05:01 netrosec

No face_recognition.py file in the folder. I've cloned the examples folder from this repo.

mvput avatar Jan 28 '18 12:01 mvput

Same problem for me, did you solve it ?

mark-srg avatar Feb 12 '18 16:02 mark-srg

@marksrg no we have not resolved this issue yet

mvput avatar Feb 13 '18 19:02 mvput

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)

ageitgey avatar Feb 13 '18 19:02 ageitgey

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']

mark-srg avatar Feb 14 '18 09:02 mark-srg

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.

ageitgey avatar Feb 14 '18 21:02 ageitgey

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.

mark-srg avatar Feb 15 '18 08:02 mark-srg

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 avatar Feb 15 '18 20:02 mvput

@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!

ageitgey avatar Feb 15 '18 21:02 ageitgey

@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.

ageitgey avatar Feb 15 '18 21:02 ageitgey

Thank you for your help ! Actually I copied the face_recognition folder to one of the folders in the PYTHONPATH and it works well.

mark-srg avatar Feb 16 '18 21:02 mark-srg

Great!

ageitgey avatar Feb 16 '18 23:02 ageitgey

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

mvput avatar Feb 17 '18 21:02 mvput

Meet same iusse, resolved. THX

mansonami avatar Mar 18 '18 00:03 mansonami

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']

JerryZhuzq avatar Jul 16 '18 10:07 JerryZhuzq

Oh! I know how to solve such mistakes. Thank you anyway!

JerryZhuzq avatar Jul 16 '18 10:07 JerryZhuzq

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 :)

ageitgey avatar Jul 16 '18 17:07 ageitgey

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']`

fabajr avatar Sep 11 '18 19:09 fabajr

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 avatar Nov 12 '18 22:11 Monica1998

@Monica1998 it looks like somehow you got the face_recognition_models package installed where face_recognition should be. How did you install things?

ageitgey avatar Nov 12 '18 22:11 ageitgey

I installed it through conda, how can i repair this. I am using anaconda

Monica1998 avatar Nov 12 '18 22:11 Monica1998

through this website : https://anaconda.org/akode/face_recognition_models

Monica1998 avatar Nov 12 '18 22:11 Monica1998

@Monica1998 Did you found any solution to the problem. I'm also using conda and imported the same package.

shyvum avatar Jan 23 '19 19:01 shyvum

Thanks. I have a function which is named "face_recognition". After I modify it, it works.

caiyuanzhe avatar Jan 29 '19 12:01 caiyuanzhe

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

shyaamramesh avatar Apr 09 '19 08:04 shyaamramesh

@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) in 1 import face_recognition_models as face_recognition 2 import dlib ----> 3 image = face_recognition.load_image_file("V2_Image100.jpg") 4 face_locations = face_recognition.face_locations(image)

AttributeError: module 'face_recognition_models' has no attribute 'load_image_file'

manoj1103 avatar Feb 20 '20 07:02 manoj1103

I rename my file from Face_Recognition.py to something else and it works.

nishant4uster1 avatar Jul 14 '20 20:07 nishant4uster1

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 👍

raybg avatar Aug 26 '20 07:08 raybg