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

module 'face_recognition' has no attribute 'load_image_file' #318

Open
mvput opened this issue Jan 22, 2018 · 37 comments
Open

module 'face_recognition' has no attribute 'load_image_file' #318

mvput opened this issue Jan 22, 2018 · 37 comments

Comments

@mvput
Copy link

mvput commented Jan 22, 2018

  • 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:~ $
@ageitgey
Copy link
Owner

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

@netrosec
Copy link

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

@mvput
Copy link
Author

mvput commented Jan 28, 2018

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

@mark-srg
Copy link

Same problem for me, did you solve it ?

@mvput
Copy link
Author

mvput commented Feb 13, 2018

@marksrg no we have not resolved this issue yet

@ageitgey
Copy link
Owner

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)

@mark-srg
Copy link

mark-srg commented Feb 14, 2018

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

@ageitgey
Copy link
Owner

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.

@mark-srg
Copy link

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.

@mvput
Copy link
Author

mvput commented Feb 15, 2018

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

@ageitgey
Copy link
Owner

@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
Copy link
Owner

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

@mark-srg
Copy link

mark-srg commented Feb 16, 2018

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

@ageitgey
Copy link
Owner

Great!

@mvput
Copy link
Author

mvput commented Feb 17, 2018

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

@mansonami
Copy link

Meet same iusse, resolved. THX

@JerryZhuzq
Copy link

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

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

@ageitgey
Copy link
Owner

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

@fabajr
Copy link

fabajr commented Sep 11, 2018

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

@Monica1998
Copy link

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 ?

@ageitgey
Copy link
Owner

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

@Monica1998
Copy link

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

@Monica1998
Copy link

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

@ShivamGoyal1899
Copy link

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

@caiyuanzhe
Copy link

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

@shyaamramesh
Copy link

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

@manoj1103
Copy link

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

@nishant4uster1
Copy link

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

@raybg
Copy link

raybg commented Aug 26, 2020

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 👍

@NEVIN-MJN
Copy link

i have the same problem here when i run the test code the output like this

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.9 (tags/v3.7.9:13c94747c7, Aug 17 2020, 18:58:18) [MSC v.1900 64 bit (AMD64)]
Python executable:
D:\monk\hotel_erp\Scripts\python.exe
Python base path:
C:\Users\user\AppData\Local\Programs\Python\Python37
Python base path (exec):
D:\monk\hotel_erp
Python system path:
['C:\Users\user\Desktop', 'C:\Users\user\AppData\Local\Programs\Python\Python37\python37.zip', 'C:\Users\user\AppData\Local\Programs\Python\Python37\DLLs', 'C:\Users\user\AppData\Local\Programs\Python\Python37\lib', 'C:\Users\user\AppData\Local\Programs\Python\Python37', 'D:\monk\hotel_erp', 'D:\monk\hotel_erp\lib\site-packages']

@kristofkakuszi
Copy link

same. I only want to use face_detection but after, installed from git both the face_recognition and the models doesnt work. I want to run this in my pycharm:

import face_recognition.face_recognition.api as face_recognition
image = face_recognition.load_image_file("picture.jpg")
face_locations = face_recognition.face_locations(image)

@Ayush21082
Copy link

Install Virtual Enviorment
pip install pipenv
Create your virtual enviorment
pipenv shell
Run the code
python your_file_name.py

I did the same and resolved my issue

@HEMANTHML
Copy link

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)

My output
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.9.12 (main, Apr 4 2022, 05:22:27) [MSC v.1916 64 bit (AMD64)]
Python executable:
C:\Users\a\anaconda3\python.exe
Python base path:
C:\Users\a\anaconda3
Python base path (exec):
C:\Users\a\anaconda3
Python s

@younasm
Copy link

younasm commented Sep 24, 2022

face_recognition version:
1.2.3

face_recognition path:
/opt/homebrew/lib/python3.9/site-packages/face_recognition/init.py

face_recognition path (alternate method):
/opt/homebrew/lib/python3.9/site-packages/face_recognition/init.py

Python version:
3.9.14 (main, Sep 6 2022, 23:16:16)
[Clang 13.1.6 (clang-1316.0.21.2.5)]
Python executable:
/opt/homebrew/bin/python3.9
Python base path:
/opt/homebrew/opt/python@3.9/Frameworks/Python.framework/Versions/3.9
Python base path (exec):
/opt/homebrew
Python system path:
['/Users/muhammadyounas/PycharmProjects/image_processing', '/Users/muhammadyounas/PycharmProjects/image_processing', '/Applications/PyCharm.app/Contents/plugins/python/helpers/pycharm_display', '/opt/homebrew/Cellar/python@3.9/3.9.14/Frameworks/Python.framework/Versions/3.9/lib/python39.zip', '/opt/homebrew/Cellar/python@3.9/3.9.14/Frameworks/Python.framework/Versions/3.9/lib/python3.9', '/opt/homebrew/Cellar/python@3.9/3.9.14/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload', '/opt/homebrew/lib/python3.9/site-packages', '/Applications/PyCharm.app/Contents/plugins/python/helpers/pycharm_matplotlib_backend']

got this output i am facing some kind of weird error don't know what's wrong.

the image is the error from this code:

import cv2 as cv
import numpy as np
import face_recognition

imgElon = face_recognition.load_image_file('ImageBasic/elon musk.jpeg')
imgElon = cv.cvtColor(imgElon, cv.COLOR_BGR2RGB)
imgTest = face_recognition.load_image_file('ImageBasic/elon test.jpeg')
imgTest = cv.cvtColor(imgTest, cv.COLOR_BGR2RGB)

cv.imshow('elon musk', imgElon)
cv.imshow('elon teste', imgTest)

cv.wiatKey(0)

Screen Shot 2022-09-25 at 2 12 54 AM

@younasm
Copy link

younasm commented Sep 25, 2022

face_recognition version: 1.2.3

face_recognition path: /opt/homebrew/lib/python3.9/site-packages/face_recognition/init.py

face_recognition path (alternate method): /opt/homebrew/lib/python3.9/site-packages/face_recognition/init.py

Python version: 3.9.14 (main, Sep 6 2022, 23:16:16) [Clang 13.1.6 (clang-1316.0.21.2.5)] Python executable: /opt/homebrew/bin/python3.9 Python base path: /opt/homebrew/opt/python@3.9/Frameworks/Python.framework/Versions/3.9 Python base path (exec): /opt/homebrew Python system path: ['/Users/muhammadyounas/PycharmProjects/image_processing', '/Users/muhammadyounas/PycharmProjects/image_processing', '/Applications/PyCharm.app/Contents/plugins/python/helpers/pycharm_display', '/opt/homebrew/Cellar/python@3.9/3.9.14/Frameworks/Python.framework/Versions/3.9/lib/python39.zip', '/opt/homebrew/Cellar/python@3.9/3.9.14/Frameworks/Python.framework/Versions/3.9/lib/python3.9', '/opt/homebrew/Cellar/python@3.9/3.9.14/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload', '/opt/homebrew/lib/python3.9/site-packages', '/Applications/PyCharm.app/Contents/plugins/python/helpers/pycharm_matplotlib_backend']

got this output i am facing some kind of weird error don't know what's wrong.

the image is the error from this code:

import cv2 as cv
import numpy as np
import face_recognition

imgElon = face_recognition.load_image_file('ImageBasic/elon musk.jpeg')
imgElon = cv.cvtColor(imgElon, cv.COLOR_BGR2RGB)
imgTest = face_recognition.load_image_file('ImageBasic/elon test.jpeg')
imgTest = cv.cvtColor(imgTest, cv.COLOR_BGR2RGB)

cv.imshow('elon musk', imgElon)
cv.imshow('elon teste', imgTest)

cv.wiatKey(0)
Screen Shot 2022-09-25 at 2 12 54 AM

Ok i find out my problem. it the image folder i write ImageBasic but it's ImagesBasic

@Yasser-Bader
Copy link

error

How to solve this error

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