ValueError: stat: path too long for Windows

I’m excited to try to run my experiment online. However, everytime I click on the sync button to move my experiment from Builder to Pavlovia I get this error:

ValueError: stat: path too long for Windows

I’ve done some searching online, and it looks like Windows limits characters to 250. I have shortened the file name, but that did not help. There are other workaround suggestions online, but I don’t understand them, so I don’t know how to apply it to PsychoPy.

Did anyone else get this error and solve it?

Thank you very much.

Just in case, here is the fully error:

Traceback (most recent call last):
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\app\builder\builder.py", line 2265, in onPavloviaSync
    self.fileExport(htmlPath=self._getHtmlPath(self.filename))
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\app\builder\builder.py", line 1682, in fileExport
    target="PsychoJS")
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\app\builder\builder.py", line 2241, in generateScript
    psyexpCompile.compileScript(infile=self.exp, version=None, outfile=experimentPath)
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.py", line 51, in compileScript
    script = thisExp.writeScript(outfile, target=targetOutput, modular=True)
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\experiment\_experiment.py", line 200, in writeScript
    self.settings.writeInitCodeJS(script, self.psychopyVersion, localDateTime, modular)
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\experiment\components\settings\__init__.py", line 494, in writeInitCodeJS
    self.prepareResourcesJS()
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\experiment\components\settings\__init__.py", line 483, in prepareResourcesJS
    resourceFiles = self.exp.getResourceFiles()
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\experiment\_experiment.py", line 799, in getResourceFiles
    thisFile = getPaths(thisParam.val)
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\experiment\_experiment.py", line 724, in getPaths
    if os.path.isfile(thisFile['abs']):
  File "C:\Program Files (x86)\PsychoPy3\lib\genericpath.py", line 30, in isfile
    st = os.stat(path)
ValueError: stat: path too long for Windows
1 Like

I’m not sure. I suspect your path isn’t actually 250 chars long but there’s probably some problem in trying to find the real path. Are any of the files shortcuts (links) instead of real files?

Maybe we can work out what filename is causing the problem by tweaking the code. Could you edit the file C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\experiment\_experiment.py and add these lines just before line724( where the problem is occurring)?

try:
    os.path.isfile(thisFile[‘abs’])
except ValueError:
    print(thisFile[‘abs’])

Thank you for your help Jon.

No, none of the files are links. The file is on my desktop, though.

I use the builder, not coding. So I added it in a coded section that occurs before line 724 (It puts it about 200 lines earlier). Line 724 is actually in the middle of a visual stimuli. At a glance, it looks like the error is exactly the same:

Traceback (most recent call last):
File “C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\app\builder\builder.py”, line 2265, in onPavloviaSync
self.fileExport(htmlPath=self.getHtmlPath(self.filename))
File “C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\app\builder\builder.py”, line 1682, in fileExport
target=“PsychoJS”)
File “C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\app\builder\builder.py”, line 2241, in generateScript
psyexpCompile.compileScript(infile=self.exp, version=None, outfile=experimentPath)
File “C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.py”, line 51, in compileScript
script = thisExp.writeScript(outfile, target=targetOutput, modular=True)
File “C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 200, in writeScript
self.settings.writeInitCodeJS(script, self.psychopyVersion, localDateTime, modular)
File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\experiment\components\settings_init
.py", line 494, in writeInitCodeJS
self.prepareResourcesJS()
File “C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\experiment\components\settings_init_.py”, line 483, in prepareResourcesJS
resourceFiles = self.exp.getResourceFiles()
File “C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 799, in getResourceFiles
thisFile = getPaths(thisParam.val)
File “C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 724, in getPaths
if os.path.isfile(thisFile[‘abs’]):
File “C:\Program Files (x86)\PsychoPy3\lib\genericpath.py”, line 30, in isfile
st = os.stat(path)
ValueError: stat: path too long for Windows

Sorry to make this post long, but I thought it might help you to see the compiled code. I copied from where your code got added (closest spot I can get in the builder), and the last line is 728 (just 4 lines after the error line so you can see how that section finishes). Clearly there is something wrong with my spacing in what you gave me as the following won’t format in here as it should…

What did I do wrong? (I did 4 spaces for first line, no spaces for 2nd, and 4 for 3rd)

os.path.isfile(thisFile['abs']) 

except ValueError:
print(thisFile[‘abs’])

m1_pr9 = visual.Rect(
win=win, name=‘m1_pr9’,
width=(allSizesXX, allSizesYY)[0], height=(allSizesXX, allSizesYY)[1],
ori=0, pos=(m1_pr9CX , m1_pr9CY),
lineWidth=1, lineColor=None, lineColorSpace=‘rgb’,
fillColor=None, fillColorSpace=‘rgb’,
opacity=1, depth=-1.0, interpolate=True)
m2_pr9 = visual.Rect(
win=win, name=‘m2_pr9’,
width=(allSizesXX, allSizesYY)[0], height=(allSizesXX, allSizesYY)[1],
ori=0, pos=(m2_pr9CX , m2_pr9CY),
lineWidth=1, lineColor=None, lineColorSpace=‘rgb’,
fillColor=None, fillColorSpace=‘rgb’,
opacity=1, depth=-2.0, interpolate=True)
m3_pr9 = visual.Rect(
win=win, name=‘m3_pr9’,
width=(allSizesXX, allSizesYY)[0], height=(allSizesXX, allSizesYY)[1],
ori=0, pos=(m3_pr9CX , m3_pr9CY),
lineWidth=1, lineColor=None, lineColorSpace=‘rgb’,
fillColor=None, fillColorSpace=‘rgb’,
opacity=1, depth=-3.0, interpolate=True)
m4_pr9 = visual.Rect(
win=win, name=‘m4_pr9’,
width=(allSizesXX, allSizesYY)[0], height=(allSizesXX, allSizesYY)[1],
ori=0, pos=(m4_pr9CX , m4_pr9CY),
lineWidth=1, lineColor=None, lineColorSpace=‘rgb’,
fillColor=None, fillColorSpace=‘rgb’,
opacity=1, depth=-4.0, interpolate=True)
m5_pr9 = visual.Rect(
win=win, name=‘m5_pr9’,
width=(allSizesXX, allSizesYY)[0], height=(allSizesXX, allSizesYY)[1],
ori=0, pos=(m5_pr9CX , m5_pr9CY),
lineWidth=1, lineColor=None, lineColorSpace=‘rgb’,
fillColor=None, fillColorSpace=‘rgb’,
opacity=1, depth=-5.0, interpolate=True)
m6_pr9 = visual.Rect(
win=win, name=‘m6_pr9’,
width=(allSizesXX, allSizesYY)[0], height=(allSizesXX, allSizesYY)[1],
ori=0, pos=(m6_pr9CX , m6_pr9CY),
lineWidth=1, lineColor=None, lineColorSpace=‘rgb’,
fillColor=None, fillColorSpace=‘rgb’,
opacity=1, depth=-6.0, interpolate=True)
m7_pr9 = visual.Rect(
win=win, name=‘m7_pr9’,
width=(allSizesXX, allSizesYY)[0], height=(allSizesXX, allSizesYY)[1],
ori=0, pos=(m7_pr9CX , m7_pr9CY),
lineWidth=1, lineColor=None, lineColorSpace=‘rgb’,
fillColor=None, fillColorSpace=‘rgb’,
opacity=1, depth=-7.0, interpolate=True)
m8_pr9 = visual.Rect(
win=win, name=‘m8_pr9’,
width=(allSizesXX, allSizesYY)[0], height=(allSizesXX, allSizesYY)[1],
ori=0, pos=(m8_pr9CX , m8_pr9CY),
lineWidth=1, lineColor=None, lineColorSpace=‘rgb’,
fillColor=None, fillColorSpace=‘rgb’,
opacity=1, depth=-8.0, interpolate=True)
m9_pr9 = visual.Rect(
win=win, name=‘m9_pr9’,
width=(allSizesXX, allSizesYY)[0], height=(allSizesXX, allSizesYY)[1],
ori=0, pos=(m9_pr9CX , m9_pr9CY),
lineWidth=1, lineColor=None, lineColorSpace=‘rgb’,
fillColor=None, fillColorSpace=‘rgb’,
opacity=1, depth=-9.0, interpolate=True)
bl_pr9 = visual.ImageStim(
win=win, name=‘bl_pr9’,
image=‘bottom_left.png’, mask=None,
ori=0, pos=[0,0], size=(allSizesXX, allSizesYY),
color=[1,1,1], colorSpace=‘rgb’, opacity=1,
flipHoriz=False, flipVert=False,
texRes=128, interpolate=True, depth=-10.0)
bl1_pr9 = visual.ImageStim(
win=win, name=‘bl1_pr9’,
image=‘bottom_left.png’, mask=None,
ori=0, pos=[0,0], size=(allSizesXX, allSizesYY),
color=[1,1,1], colorSpace=‘rgb’, opacity=1,
flipHoriz=False, flipVert=False,
texRes=128, interpolate=True, depth=-11.0)
bl2_pr9 = visual.ImageStim(
win=win, name=‘bl2_pr9’,
image=‘bottom_left.png’, mask=None,
ori=0, pos=[0,0], size=(allSizesXX, allSizesYY),
color=[1,1,1], colorSpace=‘rgb’, opacity=1,
flipHoriz=False, flipVert=False,
texRes=128, interpolate=True, depth=-12.0)
bl3_pr9 = visual.ImageStim(
win=win, name=‘bl3_pr9’,
image=‘bottom_left.png’, mask=None,
ori=0, pos=[0,0], size=(allSizesXX, allSizesYY),
color=[1,1,1], colorSpace=‘rgb’, opacity=1,
flipHoriz=False, flipVert=False,
texRes=128, interpolate=True, depth=-13.0)
bl4_pr9 = visual.ImageStim(
win=win, name=‘bl4_pr9’,
image=‘bottom_left.png’, mask=None,
ori=0, pos=[0,0], size=(allSizesXX, allSizesYY),
color=[1,1,1], colorSpace=‘rgb’, opacity=1,
flipHoriz=False, flipVert=False,
texRes=128, interpolate=True, depth=-14.0)
br_pr9 = visual.ImageStim(
win=win, name=‘br_pr9’,
image=‘bottom_right.png’, mask=None,
ori=0, pos=[0,0], size=(allSizesXX, allSizesYY),
color=[1,1,1], colorSpace=‘rgb’, opacity=1,
flipHoriz=False, flipVert=False,
texRes=128, interpolate=True, depth=-15.0)
br1_pr9 = visual.ImageStim(
win=win, name=‘br1_pr9’,
image=‘bottom_right.png’, mask=None,
ori=0, pos=[0,0], size=(allSizesXX, allSizesYY),
color=[1,1,1], colorSpace=‘rgb’, opacity=1,
flipHoriz=False, flipVert=False,
texRes=128, interpolate=True, depth=-16.0)
br2_pr9 = visual.ImageStim(
win=win, name=‘br2_pr9’,
image=‘bottom_right.png’, mask=None,
ori=0, pos=[0,0], size=(allSizesXX, allSizesYY),
color=[1,1,1], colorSpace=‘rgb’, opacity=1,
flipHoriz=False, flipVert=False,
texRes=128, interpolate=True, depth=-17.0)
br3_pr9 = visual.ImageStim(
win=win, name=‘br3_pr9’,
image=‘bottom_right.png’, mask=None,
ori=0, pos=[0,0], size=(allSizesXX, allSizesYY),
color=[1,1,1], colorSpace=‘rgb’, opacity=1,
flipHoriz=False, flipVert=False,
texRes=128, interpolate=True, depth=-18.0)
br4_pr9 = visual.ImageStim(
win=win, name=‘br4_pr9’,
image=‘bottom_right.png’, mask=None,
ori=0, pos=[0,0], size=(allSizesXX, allSizesYY),
color=[1,1,1], colorSpace=‘rgb’, opacity=1,
flipHoriz=False, flipVert=False,
texRes=128, interpolate=True, depth=-19.0)
tl_pr9 = visual.ImageStim(
win=win, name=‘tl_pr9’,
image=‘top_left.png’, mask=None,
ori=0, pos=[0,0], size=(allSizesXX, allSizesYY),
color=[1,1,1], colorSpace=‘rgb’, opacity=1,
flipHoriz=False, flipVert=False,
texRes=128, interpolate=True, depth=-20.0)

It sounds like you inserted those lines into your script. I need you to insert them into this file instead:

C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\experiment\_experiment.py

(to do that you might need to copy the file out to your desktop, where you can then edit it and then copy back to the site-packages folder)

Then run your builder experiment as it was. I want to see the line that gets printed just before the fail (which should then be a filename but I think it’s going to be broken in some way)

Hi Jon,

I’m so sorry. I should have said I’m a computer novice. I know a bit about PsychoPy from building this task. And I know enough about a computer to be dangerous, but not enough to easily do what you are asking - sorry!!

Anyway, you are right. I put it in the script. I am trying to open the file to put it in the file. I tried clicking on it. It starts to open, then crashes. I’ve tried a couple of .exe files - same thing. Is there something specific I need to try and open it with?

Hi Jon,

I was able to get the file open with notepad++. I added what you gave me to line 723, and then neither psychopy nor my task will run at all. I tried adding it and/or adjusting the spacing several ways, with the same results.

Finally I tried this. I changed this:

thisFile = {}
        if len(filePath) > 2 and (filePath[0] == "/" or filePath[1] == ":"):
            thisFile['abs'] = filePath
            thisFile['rel'] = os.path.relpath(filePath, srcRoot)
        else:
            thisFile['rel'] = filePath
            thisFile['abs'] = os.path.normpath(join(srcRoot, filePath))
        if os.path.isfile(thisFile['abs']):
            return thisFile
        else:
            return None

To:

 thisFile = {}
        if len(filePath) > 2 and (filePath[0] == "/" or filePath[1] == ":"):
            thisFile['abs'] = filePath
            thisFile['rel'] = os.path.relpath(filePath, srcRoot)
        else:
            thisFile['rel'] = filePath
            thisFile['abs'] = os.path.normpath(join(srcRoot, filePath))
        if os.path.isfile(thisFile['abs']):
            return thisFile
        else:
            print(thisFile['abs'])

It looks like it printed my entire task, and then ended with the same error:

Line 724 is:
if os.path.isfile(thisFile[‘abs’]):

Is it that my task is too large? It is over 8000 lines…

Hello all,

I’m just checking on this again. I need to get my task up this week. So, I’m in a bit of a time crunch. I apologise.

Anyway, it did not print a file name. Instead, it printed my coding from my task and then the error. I’m happy to copy and past what it printed here, but it is incredibly long.

Let me know if you would like me to do that. Or what to try now.

Thank you very much.

Hey @jon, @wineandsushi, I remember receiving this error when I attempted to create a project that was not created/saved its own empty folder. The error occurred because Pavlovia was attempting to upload all files and folders in the project directory (which included many files and folders). @wineandsushi, have you created a new empty folder for your experiment?

Hi @dvbridges,

Thank you very much for your help. Do you mean a folder just for the experiment - no images or conditions?

I did not have it in a folder by itself. I just now made a new folder with only the task, the images used in the task, and the conditions file. I got the same error.

I noticed something else today. When I click directly on the task file (the one with the psychopy logo: C:\Users\suileangorm\Desktop\BlockDesign\BD.psyexp) it opens in PsychoPy3. When I open PsychoPy3, click file>open>C:\Users\suileangorm\Desktop\BlockDesign\BD.psyexp, it will not open. PsychoPy freezes and never opens the task.

Hello again,

I am going to start a new discussion as I did get it uploaded, but it is not uploading properly.

I got it to upload by not having the experiment open in PsychoPy when I clicked the sync button. It was a complete accident that this happened.

Thank you for your help. Hopefully with my new issues, we can finally get it to run this week.

I suggest you try Long path tool is the very good program for easily delete, copy & rename long path files, error, unlock solution.
Try it and solve your problem.
I used long path tool and I solve my error, unlock problem solution.

I am helping a student with a similar problem. After inserting the code snippet @jon recommended it appears that Psychopy is using the contents of a code component as the filename, is this intended when exporting the experiment to HTML?

Example output: C:\Users\bgcra\OneDrive\Documents\E2-D-H_1\if ((mouseShowButton1DP.isPressedIn(showButtonDP) || mouseShowButton1DP.isPressedIn(showTextDP))) {
bigRecDP.opacity = 0.0;
}
if ((sliderDP.getRating() === null)) {
smallRecDP.opacity = 1.0;
} else {

This continues on for many lines.

@BradenCradock my guess in your case is that you’ve got a variable being used in the filename and that variable shares the name of your code component or something in it, but it’s hard to debug from this information.
One things ot note is that isPressedIn isn’t yet supported in the web studies. You have to use the slightly longer if statement of this and I think that should then correctly work in both local and online

if sum(mouseShowButton1DP.buttons) and showButtonDP.contains(mouseShowButton1DP):

but that isn’t the issue with the long filename. That’s coming from something else to do with a name clash I believe.

Thank you Jon, that was the problem. I have also informed the student to use the substitute for isPressedIn.

@jon, or anyone else who can help:
I got a similar error when trying to upload my current experiment, I went and added the line of code that you had suggested above to debug. It seems like part of the issue is my custom code is messing things up, but not sure how or why:

Welcome to PsychoPy3!
v2020.1.3
20.2626     INFO     Loaded monitor calibration from ['2020_05_21 11:33']
Generating PsychoJS script...

C:\Users\zhbre\Desktop\online_recoblast\code
C:\Users\zhbre\Desktop\online_recoblast\Auto->JS
C:\Users\zhbre\Desktop\online_recoblast
C:\Users\zhbre\Desktop\online_recoblast
C:\Users\zhbre\Desktop\online_recoblast
C:\Users\zhbre\Desktop\online_recoblast
C:\Users\zhbre\Desktop\online_recoblast
C:\Users\zhbre\Desktop\online_recoblast\thisExp=psychoJS.experiment;
win=psychoJS.window;
event=psychoJS.eventManager;
Array.prototype.append = [].push;
Object.prototype.upper = "".toUpperCase;
shuffle = util.shuffle;

randint = function(min, maxplusone) {
  return Math.floor(Math.random() * (maxplusone - min) ) + min;
}

C:\Users\zhbre\Desktop\online_recoblast
C:\Users\zhbre\Desktop\online_recoblast
C:\Users\zhbre\Desktop\online_recoblast
C:\Users\zhbre\Desktop\online_recoblast
C:\Users\zhbre\Desktop\online_recoblast\code_init
C:\Users\zhbre\Desktop\online_recoblast\Auto->JS
Traceback (most recent call last):
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.py", line 74, in generateScript
    compileScript(infile=exp, version=None, outfile=filename)
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.py", line 245, in compileScript
    _makeTarget(thisExp, outfile, targetOutput)
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.py", line 217, in _makeTarget
    script = thisExp.writeScript(outfile, target=targetOutput, modular=True)
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment\_experiment.py", line 209, in writeScript
    localDateTime, modular)
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment\components\settings\__init__.py", line 516, in writeInitCodeJS
    self.prepareResourcesJS()
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment\components\settings\__init__.py", line 504, in prepareResourcesJS
    resourceFiles = self.exp.getResourceFiles()
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment\_experiment.py", line 830, in getResourceFiles
    thisFile = getPaths(thisParam.val)
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment\_experiment.py", line 755, in getPaths
    if os.path.isfile(thisFile['abs']):
  File "C:\Program Files\PsychoPy3\lib\genericpath.py", line 30, in isfile
    st = os.stat(path)
ValueError: stat: path too long for Windows