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

Error with Spyder IPython Shell - AttributeError: 'NoneType' object has no attribute 'fileno' #191

Closed
shahrukhkhan489 opened this issue Dec 22, 2019 · 23 comments
Labels
type:Bug Something isn't working

Comments

@shahrukhkhan489
Copy link

This issue is on MacOS. Have checked Issue #8668, and the pull request fix seems to be there.

Error in callback <function sys_pipes_forever at 0x11a3477a0> (for pre_execute):
Traceback (most recent call last):

  File "/Users/skhan/opt/anaconda3/lib/python3.7/site-packages/wurlitzer.py", line 331, in sys_pipes_forever
    _mighty_wurlitzer.__enter__()

  File "/Users/skhan/opt/anaconda3/lib/python3.7/contextlib.py", line 112, in __enter__
    return next(self.gen)

  File "/Users/skhan/opt/anaconda3/lib/python3.7/site-packages/wurlitzer.py", line 298, in pipes
    with w:

  File "/Users/skhan/opt/anaconda3/lib/python3.7/site-packages/wurlitzer.py", line 151, in __enter__
    pipe = self._setup_pipe('stdout')

  File "/Users/skhan/opt/anaconda3/lib/python3.7/site-packages/wurlitzer.py", line 100, in _setup_pipe
    real_fd = getattr(sys, '__%s__' % name).fileno()

AttributeError: 'NoneType' object has no attribute 'fileno'```

Have taken a reference from https://github.com/spyder-ide/spyder-kernels/commit/e3847f1d167a49b35d1307db21ad57fb868d34c5
@ccordoba12
Copy link
Member

I think this is fixed in the latest wurlitzer version. Please update it and try again.

@ncneal
Copy link

ncneal commented Jan 30, 2020

I just updated to Spyder 4 and am getting the following on MacOS:

Traceback (most recent call last):

  File "/Users/nickneal/anaconda3/lib/python3.7/site-packages/wurlitzer.py", line 339, in sys_pipes_forever
    _mighty_wurlitzer.__enter__()

  File "/Users/nickneal/anaconda3/lib/python3.7/contextlib.py", line 112, in __enter__
    return next(self.gen)

  File "/Users/nickneal/anaconda3/lib/python3.7/site-packages/wurlitzer.py", line 306, in pipes
    with w:

  File "/Users/nickneal/anaconda3/lib/python3.7/site-packages/wurlitzer.py", line 158, in __enter__
    pipe = self._setup_pipe('stdout')

  File "/Users/nickneal/anaconda3/lib/python3.7/site-packages/wurlitzer.py", line 107, in _setup_pipe
    real_fd = getattr(sys, '__%s__' % name).fileno()

AttributeError: 'NoneType' object has no attribute 'fileno'

I have the latest wurlitzer version but am still getting this message anytime I use the console.

Edit: downgraded Spyder to 3.3.6 and still have the same issue

@ccordoba12
Copy link
Member

@impact27, could you help us with this one? We could simply catch the error and print an informative message about it.

@impact27
Copy link
Contributor

I don't think this touches spyder code, so I'm not sure where we could catch that. We should open an issue on https://github.com/minrk/wurlitzer. Do you have a way of reproducing the error?

@impact27
Copy link
Contributor

I opened minrk/wurlitzer#36

@ccordoba12
Copy link
Member

Thanks @impact27!

@muhlbach
Copy link

I'm experiencing the same issue with wurlitzer=2.0.0, spyder=4.0.1 and python=3.7.0. I'm running macOS 10.15.3. Any updates or fixes?

Python 3.7.0 (default, Jun 28 2018, 07:39:16) 
Type "copyright", "credits" or "license" for more information.

IPython 7.12.0 -- An enhanced Interactive Python.
Error in callback <function sys_pipes_forever at 0x11e652320> (for pre_execute):
Traceback (most recent call last):

  File "/opt/anaconda3/lib/python3.7/site-packages/wurlitzer.py", line 339, in sys_pipes_forever
    _mighty_wurlitzer.__enter__()

  File "/opt/anaconda3/lib/python3.7/contextlib.py", line 112, in __enter__
    return next(self.gen)

  File "/opt/anaconda3/lib/python3.7/site-packages/wurlitzer.py", line 306, in pipes
    with w:

  File "/opt/anaconda3/lib/python3.7/site-packages/wurlitzer.py", line 158, in __enter__
    pipe = self._setup_pipe('stdout')

  File "/opt/anaconda3/lib/python3.7/site-packages/wurlitzer.py", line 107, in _setup_pipe
    real_fd = getattr(sys, '__%s__' % name).fileno()

AttributeError: 'NoneType' object has no attribute 'fileno'


@impact27
Copy link
Contributor

@muhlback
Do you have any idea why sys.__stdout__ is None in your case? Can you check if this is the case?

@muhlbach
Copy link

@impact27:

Do you mean like this?


import sys

sys.__stdout__
Error in callback <function sys_pipes_forever at 0x119208320> (for pre_execute):
Traceback (most recent call last):

  File "/opt/anaconda3/lib/python3.7/site-packages/wurlitzer.py", line 339, in sys_pipes_forever
    _mighty_wurlitzer.__enter__()

  File "/opt/anaconda3/lib/python3.7/contextlib.py", line 112, in __enter__
    return next(self.gen)

  File "/opt/anaconda3/lib/python3.7/site-packages/wurlitzer.py", line 306, in pipes
    with w:

  File "/opt/anaconda3/lib/python3.7/site-packages/wurlitzer.py", line 158, in __enter__
    pipe = self._setup_pipe('stdout')

  File "/opt/anaconda3/lib/python3.7/site-packages/wurlitzer.py", line 107, in _setup_pipe
    real_fd = getattr(sys, '__%s__' % name).fileno()

AttributeError: 'NoneType' object has no attribute 'fileno'

@impact27
Copy link
Contributor

You can do:

import sys
print(str(sys.__stdout__))

I can reproduce this bug if I write (Which is probably not a good idea):

sys.__stdout__ = None

@impact27
Copy link
Contributor

So is this a bug you get on a used console that ran code that might have done sys.__stdout__ = None or do you get this on a new console?

@muhlbach
Copy link

I confirm that this gives None:

import sys
print(str(sys.__stdout__))
Error in callback <function sys_pipes_forever at 0x12043a320> (for pre_execute):
Traceback (most recent call last):

  File "/opt/anaconda3/lib/python3.7/site-packages/wurlitzer.py", line 339, in sys_pipes_forever
    _mighty_wurlitzer.__enter__()

  File "/opt/anaconda3/lib/python3.7/contextlib.py", line 112, in __enter__
    return next(self.gen)

  File "/opt/anaconda3/lib/python3.7/site-packages/wurlitzer.py", line 306, in pipes
    with w:

  File "/opt/anaconda3/lib/python3.7/site-packages/wurlitzer.py", line 158, in __enter__
    pipe = self._setup_pipe('stdout')

  File "/opt/anaconda3/lib/python3.7/site-packages/wurlitzer.py", line 107, in _setup_pipe
    real_fd = getattr(sys, '__%s__' % name).fileno()

AttributeError: 'NoneType' object has no attribute 'fileno'

None

This happens when I start a new console.

@impact27
Copy link
Contributor

I don't really understand how this is possible:

Note

Under some conditions stdin, stdout and stderr as well as the original values stdin, stdout and stderr can be None. It is usually the case for Windows GUI apps that aren’t connected to a console and Python apps started with pythonw.

@muhlbach
Copy link

Also None when I print sys.__stdout__.

I don't run any code on start up:
Screen Shot 2020-02-13 at 16 11 54

@impact27
Copy link
Contributor

What about:

import sys
print(str(sys.__stdout__), str(sys.stdout), str(sys.__stderr__), str(sys.stderr))

@muhlbach
Copy link


import sys
print(str(sys.__stdout__), str(sys.stdout), str(sys.__stderr__), str(sys.stderr))
Error in callback <function sys_pipes_forever at 0x11833a320> (for pre_execute):
Traceback (most recent call last):

  File "/opt/anaconda3/lib/python3.7/site-packages/wurlitzer.py", line 339, in sys_pipes_forever
    _mighty_wurlitzer.__enter__()

  File "/opt/anaconda3/lib/python3.7/contextlib.py", line 112, in __enter__
    return next(self.gen)

  File "/opt/anaconda3/lib/python3.7/site-packages/wurlitzer.py", line 306, in pipes
    with w:

  File "/opt/anaconda3/lib/python3.7/site-packages/wurlitzer.py", line 158, in __enter__
    pipe = self._setup_pipe('stdout')

  File "/opt/anaconda3/lib/python3.7/site-packages/wurlitzer.py", line 107, in _setup_pipe
    real_fd = getattr(sys, '__%s__' % name).fileno()

AttributeError: 'NoneType' object has no attribute 'fileno'

None <ipykernel.iostream.OutStream object at 0x117dec150> <_io.TextIOWrapper name='<stderr>' mode='w' encoding='UTF-8'> <ipykernel.iostream.OutStream object at 0x117dec0d0>

Btw thank you for your persistency!

@impact27
Copy link
Contributor

Check if you have the latest version of ipykernel maybe?
Workaround:

import sys; sys.__stdout__ = sys.__stderr__

@muhlbach
Copy link

I'm running with ipykernel=5.1.4 (py37h39e3cac_0), which should be the latest version.

@goanpeca goanpeca added the type:Bug Something isn't working label May 5, 2020
@yotamcons
Copy link

I have the same issue with spyder 3.3.6 and python 3.6 on macOS 10.15.4
it goes away if I exit Spyder and than reopen

@JM-RPC
Copy link

JM-RPC commented May 26, 2020

I ran into the same error when calling Sypder3 from a bash shell (Python 3.7.4 IPython 7.14.0). I noticed it was complaining about pipes, so I did the naive thing, invoked Spyder sending stdout and stderr to /dev/null e.g:

/usr/bin/spyder3 &>/dev/null &

and the problem seemed to go away.

@impact27
Copy link
Contributor

@ccordoba12 Should we disable wurlitzer if stdout is disabled?

@impact27
Copy link
Contributor

Fixed by minrk/wurlitzer#44

@ccordoba12
Copy link
Member

Great! Closing this one then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants