2
votes

My original script is bigger than this, but I discovered this alone causes the exact same error. First post here (I think). So apologies if format not right.

for a in range(4000):
    for b in range(200):
        print('4000:' + str(a))
        print('201:' + str(b))

And I get all this as errors. I'm Spyder with the Ipython console.

File "", line 1, in runfile('C:/Users/me/Documents/file.py', wdir='C:/Users/me/Documents')

File "C:\Users\me\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 714, in runfile execfile(filename, namespace)

File "C:\Users\me\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 89, in execfile exec(compile(f.read(), filename, 'exec'), namespace)

File "C:/Users/me/Documents/file.py", line 35, in print('4000:' + str(a))

File "C:\Users\me\Anaconda3\lib\site-packages\ipykernel\iostream.py", line 317, in write self._buffer.write(string)

ValueError: I/O operation on closed file

1
This seems to be an issue with spyder's execfile rather than your actual code. Try running it in a non-spyder terminal...juanpa.arrivillaga
Seems to be a known bug in IPython, actually. Are you doing any dark magic with sys.stdout, by any chance? What version of Ipython are you using? It may have been fixed in recent versions, and you could try just updating Ipython...juanpa.arrivillaga
Yeah. Using command prompt seems to work. ThanksGimeno_2000
Dark magic? Ha. No. Not changed anything if that's what you mean. IPython 4.2.0. But the regular python console also came up with similar problems with SpyderGimeno_2000

1 Answers

0
votes

(Spyder developer here) This bug is not a Spyder bug but an ipykernel bug. It was fixed in ipykernel version 4.4, released in August 2016.

So please be sure to update to the latest ipykernel by running this command in a terminal (i.e. cmd.exe)

conda update ipykernel

Note: It'd be good if you could update to the latest Spyder release too because you're still using version 2.3 and our latest one is 3.1.4.