"Couldn't find image ; check path?" ONLY WHEN THE PATH IS CORRECT

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): 2022.2.3
Standard Standalone? (y/n) If not then what?: y
What are you trying to achieve?: display images

I know this sounds like a trivial question, and it often turns out that somebody misspelled the path. However, I truly believe this is really not the case here, and it almost feels like a PsychoPy bug.

For context: I programmed a complex experiment, where the first routine determines the next routines. In my first routine, the participants see faces in particular conditions. In later routines, they read sentences that are accompanied by faces, and the condition of the sentence must match the face that was presented in that same condition earlier.

In a nutshell, I use this code in my first routine:

Begin Experiment

speakerimageCN = []
speakerimageCF = []
speakerimageIN = []
speakerimageIF = []

End Routine

if speaker_cond == 'CAN native':
   speakerimageCN = speakerimage
   thisExp.addData('speakerimageCN', speakerimageCN)
elif speaker_cond == 'CAN foreign':
    speakerimageCF = speakerimage
    thisExp.addData('speakerimageCF', speakerimageCF)
elif speaker_cond == 'IMM native':
    speakerimageIN = speakerimage
    thisExp.addData('speakerimageIN', speakerimageIN)
else:
    speakerimageIF = speakerimage
    thisExp.addData('speakerimageIF', speakerimageIF)

I know for a fact that that all my variables are properly recorded (because I checked it with " thisExp.addData", I will attach the screenshot of the csv)

Now, in my second routine, I use this code to display images

if speaker_cond == 'CAN native':
    speaker_face.setImage('images/' + speakerimageCN + '.jpg')
elif speaker_cond == 'CAN foreign':
    speaker_face.setImage('images/'+ speakerimageCF + '.jpg')
elif speaker_cond == 'IMM native':
    speaker_face.setImage('images/'+ speakerimageIN + '.jpg')
else:
    speaker_face.setImage('images/'+ speakerimageIF + '.jpg')

And each time I reach that part I get this error:

Traceback (most recent call last):
  File "G:\My Drive\World knowledge\PsychoPy experiment\WK_LAB - Copy_lastrun.py", line 1428, in <module>
    speaker_face.setImage('')
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\image.py", line 416, in setImage
    setAttribute(self, 'image', value, log)
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\tools\attributetools.py", line 134, in setAttribute
    setattr(self, attrib, value)
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\tools\attributetools.py", line 27, in __set__
    newValue = self.func(obj, value)
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\image.py", line 382, in image
    self.isLumImage = self._createTexture(
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\basevisual.py", line 1022, in _createTexture
    raise IOError(msg % (tex, os.path.abspath(tex)))
**OSError: Couldn't find image ; check path? (tried: G:\My Drive\World knowledge\PsychoPy experiment)**
################ Experiment ended with exit code 1 [pid:28716] #################

I know that the path is correct, I checked it a thousand times. Also, when I make an error in the path on purpose (say, ‘imagess/’+ speakerimageIF + ‘.jpg’) I get a different error:

Traceback (most recent call last):
  File "G:\My Drive\World knowledge\PsychoPy experiment\WK_LAB - Copy_lastrun.py", line 1419, in <module>
    speaker_face.setImage('imagess/'+ speakerimageCF + '.jpg')
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\image.py", line 416, in setImage
    setAttribute(self, 'image', value, log)
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\tools\attributetools.py", line 134, in setAttribute
    setattr(self, attrib, value)
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\tools\attributetools.py", line 27, in __set__
    newValue = self.func(obj, value)
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\image.py", line 382, in image
    self.isLumImage = self._createTexture(
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\basevisual.py", line 1022, in _createTexture
    raise IOError(msg % (tex, os.path.abspath(tex)))
**OSError: Couldn't find image imagess/WF1.jpg; check path? (tried: G:\My Drive\World knowledge\PsychoPy experiment\imagess\WF1.jpg)**
################# Experiment ended with exit code 1 [pid:7628] #################

I am really racking my brain here as to why this is happening. It seems like when the path is correct it just doesn’t accept it and crashes??? I would appreciate any help you can offer

I am having a similar problem.

Please let me know if you find a solution. I’ve been at it for days to no avail

Okay, I finally fixed it by setting the image component to “constant” and putting the code for image display into “begin routine”. Hope that helps!

If you compare your two error messages you will see that the second one has the file name whereas the first one is blank. Therefore, the issue is with the variable used to contain the file name, not the path to the folder.

Greetings! Check this out! I renamed all my images to make the file name the same as those in the error window, as I show you below.


(i.e. I changed the names of all the files from ABCD.JPG to 程序用文件\ABCD.JPG to uniform file names)

Hope it works!

I have also encountered a similar issue before.
At that time, I was using a cloud storage to store materials. The G drive, which appeared to be a local hard drive and could be opened locally, was actually a virtual disk created by mounting the cloud storage to the local system. Psychopy found the corresponding files on the virtual disk, but it lacked the necessary permissions to access the files, resulting in an IOError.
However, when I transferred the materials to the local system and carefully checked the file path by considering the use of ‘/’ and '' correctly, the IOError disappeared.
Based on the information you provided, it is difficult to determine if you are facing the same issue as mine. However, I sincerely hope that this solution will be effective in resolving your problem. If the solution does not work, I would suggest reviewing your temporary workaround (compile to python script) and comparing it with the previously generated .py file, as identifying the differences between the two may help you pinpoint the issue.

Your approach could potentially be the correct solution. If I understand correctly, it seems that PsychoPy did not read the .jpg file in the ‘images’ folder, but instead read a file named ‘images/speakerimageIF.jpg’ in the parent directory of the ‘images’ folder?

Yes, exactly! That’s what I meant. Sorry for the expression, I’m not that good at English and I was too excited to share my success lol.