[open] AttributeError: 'module' object has no attribute 'sample'
edited February 2015 in PyGaze
I'am working on a gaze-contingent project and was really happy to read that PyGaze can help me because I just begin to use Python. But I have troubles with the following code which I created to achieve my purpose :
# create display object disp = libscreen.Display() # create eyetracker object tracker = eyetracker.EyeTracker(disp) def Affichage_glob(image, score): window.fill(bg_col) gaze_contingent() face(image) pygame.display.flip() ti_0 = datetime.datetime.fromtimestamp(time.time()) pygame.time.wait(1000) window.fill(bg_col) scale() he, we = scale() arrow(he, we, score) pygame.display.flip() ti_1 = datetime.datetime.fromtimestamp(time.time()) ti_2 = time.time() pygame.time.wait(30) return ti_0, ti_1, ti_2 trou = pygame.image.load('trou.png') wg, hg = trou.get_size() def gaze_contingent(): x, y = eyetracker.sample() window.blit(trou, [- wg/2+c_x, - hg/2+c_y]) pygame.display.flip()
I obtain the following error message :
File "F:\Programme_python\gaze_contingent.py", line 320, in <module> ti_0, ti_1, ti_2 = Affichage_glob(image, score) File "F:\Programme_python\gaze_contingent.py", line 216, in Affichage_glob gaze_contingent() File "F:\Programme_python\gaze_contingent.py", line 272, in gaze_contingent x, y = eyetracker.sample() AttributeError: 'module' object has no attribute 'sample'
Can you explain to me why, and how to solve it ?
Many thanks for your help !
I am very sorry for my stupid question, I just forgot to switch the DUMMYMODE from False to True...
But I have now a new error :
I have looked for that module in internet but found nothing.
Actually, your first error did not arise from not using DUMMYMODE. In dummy mode, you should still be able to get samples (the mouse serves as a simulated eye tracker).
What did cause the error, is that you use
tracker.sample. The former refers to the entire module
eyetracker, whereas the latter refers to the instance
tracker(which is the one you want to use to get samples).
Additionally, you seem to be mixing PyGame with PyGaze functions, which is not necessarily wrong, but it kind of defeats the purpose of PyGaze providing you the same functionality without directly having to use PyGame (you can opt for a PsychoPy back-end as well).
Finally, the import error suggests that you might not have installed the Tobii SDK properly. The weird path ("F:\Programme_python\tobii") seems to suggest the same thing. Usually, installed modules should go to the site-packages directory of your Python installation.
thanks for your answer !
I don't understand in this case why in the example files shooting_game.py there is eyetracker.sample()... (line 60) what is the difference with what I am doing ?
I have written all my code, in the perspective to take measures by the Eye-Tribe, when we realize that the Eye-Tribe was not the better device for our work and that adding a gaze-contingent function will be great... That's only at that time I discover Pygaze. It take me a very long time, I hope I wont have to rewrite everything.
I have all uninstall and reinstall, that's ok now.
But I have a new problem : my program start, I have a message "Start calibration" and a window with a light brown fond color and a green circle appear. Then, it freeze and nothing else append.
I have the same problem when I try to run simple_tracker_experiment.py.
I have check the eye-tracker, the calibration can be done well with the TobiiStudio.
Sorry, I forgot to give you the error message about my last problem :
Traceback (most recent call last):
File "F:\Programme_python\simple_tracker_experiment.py", line 49, in
File "C:\Python27\lib\site-packages\pygaze\libtobii.py", line 211, in calibrate
AttributeError: 'str' object has no attribute 'fill'
It's simply because there is no attribute with the name you called, for that Object. This means that you got the error when the "module" does not contain the method you are calling. But it is evident that the method is there, which leads to believe that may be the method was added by you in the python source code after you had already imported the file (module). Or, some times packages get deprecated and they rename some functions. If that is true, then you may want to exit and reimport the module once again to be able to access the new method.
You can do it in another way to reimport the module with changes without having to exit the interpreter is to do the following: