spyder: Error when getting the namespace view from the kernel

Description

What steps will reproduce the problem?

What is the expected output? What do you see instead?

Please provide any additional information below

  File "/anaconda/lib/python3.6/site-packages/qtconsole/base_frontend_mixin.py", line 163, in _dispatch
    handler(msg)
  File "/anaconda/lib/python3.6/site-packages/spyder/widgets/ipythonconsole/namespacebrowser.py", line 214, in _handle_execute_reply
    self.handle_exec_method(msg)
  File "/anaconda/lib/python3.6/site-packages/spyder/widgets/ipythonconsole/shell.py", line 311, in handle_exec_method
    view = ast.literal_eval(data['text/plain'])
  File "/anaconda/lib/python3.6/ast.py", line 85, in literal_eval
    return _convert(node_or_string)
  File "/anaconda/lib/python3.6/ast.py", line 66, in _convert
    in zip(node.keys, node.values))
  File "/anaconda/lib/python3.6/ast.py", line 65, in <genexpr>
    return dict((_convert(k), _convert(v)) for k, v
  File "/anaconda/lib/python3.6/ast.py", line 66, in _convert
    in zip(node.keys, node.values))
  File "/anaconda/lib/python3.6/ast.py", line 65, in <genexpr>
    return dict((_convert(k), _convert(v)) for k, v
  File "/anaconda/lib/python3.6/ast.py", line 84, in _convert
    raise ValueError('malformed node or string: ' + repr(node))
ValueError: malformed node or string: <_ast.Call object at 0x12f124400>

Version and main components

  • Spyder Version: 3.2.0
  • Python Version: 3.6.1
  • Qt Versions: 5.6.2, PyQt5 5.6 on Darwin

Dependencies

pyflakes >=0.6.0 :  1.5.0 (OK)
pycodestyle >=2.3:  2.3.1 (OK)
pygments >=2.0   :  2.2.0 (OK)
pandas >=0.13.1  :  0.20.1 (OK)
numpy >=1.7      :  1.12.1 (OK)
sphinx >=0.6.6   :  1.5.6 (OK)
rope >=0.9.4     :  0.9.4-1 (OK)
jedi >=0.9.0     :  0.10.2 (OK)
psutil >=0.3     :  5.2.2 (OK)
nbconvert >=4.0  :  5.1.1 (OK)
sympy >=0.7.3    :  1.0 (OK)
cython >=0.21    :  0.25.2 (OK)
qtconsole >=4.2.0:  4.3.0 (OK)
IPython >=4.0    :  5.3.0 (OK)
pylint >=0.25    :  1.6.4 (OK)

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 24 (15 by maintainers)

Most upvoted comments

@dalthviz, giving that this is a very critical error (because it makes the IPython console unusable), I think we should catch all errors when trying to use ast.literal_eval in handle_exec_method (specifically in get_namespace_view and get_var_properties) and raise a new error that includes the values of view and properties.

I think something like this should work:

if 'get_namespace_view' in method:
    if data is not None and 'text/plain' in data:
        try:
            view = ast.literal_eval(data['text/plain'])
        except Exception as error:
            error = to_text_string(error)
            view = to_text_string(data['text/plain'])
            text = "An error occurred while getting a "
                   "representation of your namespace. "
                   "The error was {0} and the obtained "
                   "value was {1}".format(error, view)
            raise ValueError(text)
    else:
        view = None
    self.sig_namespace_view.emit(view)

This way we will be able to better understand what the kernel is sending to Spyder.

However, the problem with this is we would also need the code a user is running in the console to make sense of the namespace representation we get in the error.

Let’s wait to see if more errors like this one are reported in the future before implementing this solution.

@mitchell5, I really don’t understand where this error is coming from. If you want to help us to solve it, please follow these steps:

  1. Put a line with print([data['text/plain']]) before line 311 in /anaconda/lib/python3.6/site-packages/spyder/widgets/ipythonconsole/shell.py.
  2. Restart Spyder.
  3. Go to the menu View > Panes > Internal console and copy the text printed there after you run 1+1 in a console.
  4. Post the result here.

With that info we will be able to understand why the console is not returning the result Spyder expects.

Thank you, it seems like it solved the problem 😃

On 30 Jul 2017, at 17:22, Carlos Cordoba notifications@github.com wrote:

Then, please run

spyder --reset in a terminal and try again.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/spyder-ide/spyder/issues/4855#issuecomment-318912433, or mute the thread https://github.com/notifications/unsubscribe-auth/AHHNarR3IkrCUgLVnlHe4tHPUWAn84Wwks5sTK2zgaJpZM4OnX8k.

@dalthviz, please take a look at this one.