Spyder: Error when getting the namespace view from the kernel

Created on 29 Jul 2017  Â·  24Comments  Â·  Source: spyder-ide/spyder

Description

What steps will reproduce the problem?



    1. 2.
  1. 3.

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)

IPython Console Bug

All 24 comments

What were you evaluating when you get this error?

Hi,
Today I made some package downloads and updates:

conda install -c anaconda nltk

conda install -c conda-forge textblob

conda install -c conda-forge spacy

conda install -c anaconda gensim

After that I am getting these error messages as I am trying to parse RDF/XML files like:

import rdflib
from rdflib import Graph

fileid = "http%253A%252F%252Fboards.ie%252Fvbulletin%252Fsioc.php%253Fsioc_type%253Dthread%2526sioc_id%253D9"

Parsing the file

g = Graph()
g.parse("boards.ie SIOC Datasets/1998/threads/" + fileid,format = "xml")

tokenizing the message content

import pprint
for stmt in g:
pprint.pprint(stmt)

Also my Variable Explorer does not show any variables.

Thank you
Deniz

On 29 Jul 2017, at 18:12, Carlos Cordoba notifications@github.com wrote:

What were you evaluating when you get this error?

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

Thanks for the reproducible code. We'll take a look at this as soon as possible.

Also my Variable Explorer does not show any variables.

That's caused by the error you reported.

@dalthviz, please take a look at this one.

Hi @mitchell5 I tried the updates and the code you provided but it doesn´t run (maybe the parse part and the fileid are not correct) it says it can't find the source.

However, running something like

from rdflib import Graph 
## Parsing the file 
g = Graph() 
g.parse("http://www.w3.org/2000/10/swap/test/meet/blue.rdf",format = "xml")
# tokenizing the message content 
import pprint 
for stmt in g:
    pprint.pprint(stmt)

works for me, and the last tuple (saved in the stmt var) is shown in the variable explorer:

imagen

Could you try again with the code above and see if the error still happen, maybe could be something in the source are you trying to parse? all the info will be greatly appreciated :)

Hi Daniel,
Thank you for your interest in the problem. I am still getting similar error messages although I get the evaluation right after I ran my code.

The error I get now:

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
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
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 0x1469c9518>

On 29 Jul 2017, at 23:21, Daniel Althviz Moré notifications@github.com wrote:

Hi @mitchell5 https://github.com/mitchell5 I tried the updates and the code you provided but it doesn´t run (maybe the parse part and the fileid are not correct) it says it can't find the source.

However, running something like

from rdflib import Graph

Parsing the file

g = Graph()
g.parse("http://www.w3.org/2000/10/swap/test/meet/blue.rdf",format = "xml")

tokenizing the message content

import pprint
for stmt in g:
pprint.pprint(stmt)
works for me, and the last tuple (saved in the stmt var) is shown in the variable explorer:

https://user-images.githubusercontent.com/16781833/28748582-010349ba-7481-11e7-8d3c-09ba4e0cf64e.png
Could you try again with the code above and see if the error still happen, maybe could be something in the source are you trying to parse? all the info will be greatly appreciated :)

—
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-318863553, or mute the thread https://github.com/notifications/unsubscribe-auth/AHHNakSW_E13urSnJgY33zlZYaNw2mJyks5sS7BpgaJpZM4OnX8k.

@mitchell5, please provide a working example if you want us to fix this. For example

fileid = "http%253A%252F%252Fboards.ie%252Fvbulletin%252Fsioc.php%253Fsioc_type%253Dthread%2526sioc_id%253D9"

is not a valid URL, so the rest of your code fails.

Hi,
The files are on my local. But it does not matter what code I ran, I ran into the same errors. Recently, the program just shut itself.

Thanks in advance for the help,

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
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
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 0x13151af60>

On 30 Jul 2017, at 16:02, Carlos Cordoba notifications@github.com wrote:

@mitchell5 https://github.com/mitchell5, please provide a working example if you want us to fix this. For example

fileid = "http%253A%252F%252Fboards.ie%252Fvbulletin%252Fsioc.php%253Fsioc_type%253Dthread%2526sioc_id%253D9"
is not a valid URL, so the rest of your code fails.

—
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-318907523, or mute the thread https://github.com/notifications/unsubscribe-auth/AHHNapTU9V_dQ3EpGdx_6UPXMpXdKmtnks5sTJrugaJpZM4OnX8k.

So does is this error appear for you even if you run 1+1 in a console?

Yes, it does

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

So does is this error appear for you even if you run 1+1 in a console?

—
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-318911655, or mute the thread https://github.com/notifications/unsubscribe-auth/AHHNakST949N3W9R8HTO2piUHuZQpeUNks5sTKpvgaJpZM4OnX8k.

And are using a different Python interpreter in

Preferences > Python interpreter

?

I am using the default one ?

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

And are using a different Python interpreter in

Preferences > Python interpreter
?

—
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-318912035, or mute the thread https://github.com/notifications/unsubscribe-auth/AHHNanpFD65zlshEgiJtIfRs5u2dK6J-ks5sTKvggaJpZM4OnX8k.

Then, please run

spyder --reset

in a terminal and try again.

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.

Great! Thanks for letting us know about it.

Hi,
Sorry for bothering again, but I get the same problem even when I run 1+1. I tried to reset spyder(spyder --reset) but it didn’t solve the issue this time.

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
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
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 0x12bb9eeb8>

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

Closed #4855 https://github.com/spyder-ide/spyder/issues/4855.

—
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#event-1184842877, or mute the thread https://github.com/notifications/unsubscribe-auth/AHHNavoI3dGaDn0YtERdakXx-vudqS5uks5sTLF2gaJpZM4OnX8k.

Hi @mitchell5 , maybe you could try to create another env? (you can do it with something like conda create -n new_env anaconda) and see if in the Spyder of that env the error persists? Also, did you install any library with pip? I think this is some kind of installation issue.

Hi,
Yes, before I installed anaconda, my system had python 2 and I installed python 3 and some libraries with pip3. I was using python with IDLE until I installed anaconda environment. I tried to create new environment but nothing has changed. Sorry for taking so much time. What would you suggest for me to do in this situation?

Thanks in advance

On 30 Jul 2017, at 23:46, Daniel Althviz Moré notifications@github.com wrote:

Hi @mitchell5 https://github.com/mitchell5 , maybe you could try to create another env? (you can do it with something like conda create -n new_env anaconda) and see if in the Spyder of that env the error persists? Also, did you install any library with pip? I think this is some kind of installation issue.

—
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-318935327, or mute the thread https://github.com/notifications/unsubscribe-auth/AHHNah7hlgYBTeUBUFY1DIK-dVL9dIwlks5sTQfigaJpZM4OnX8k.

Maybe try to uninstall Anaconda, then try to reinstall it (be sure to install it in a place like /home/<your-user>/Anaconda3). The following links maybe can help in this:

https://conda.io/docs/install/full.html#linux-anaconda-install
https://docs.continuum.io/anaconda/install/linux

And don't you worry we are glad to help :)

@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.

@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.

Hi,
Thank you for the direction. I did what you have said below:

Spyder Internal Console

This console is used to report application
internal errors and to inspect Spyder
internals with the following commands:
spy.app, spy.window, dir(spy)

Please don't use it to run your code

WARNING:traitlets:kernel died: 6.001140832901001

But before that I uninstalled Anaconda and reinstalled it. Now, I got another error but I think this is because of my application:

Spyder Internal Console

This console is used to report application
internal errors and to inspect Spyder
internals with the following commands:
spy.app, spy.window, dir(spy)

Please don't use it to run your code

WARNING:traitlets:kernel died: 6.001140832901001
Traceback (most recent call last):
File "/Users/denizgokalp/anaconda/lib/python3.6/site-packages/qtconsole/base_frontend_mixin.py", line 163, in _dispatch
handler(msg)
File "/Users/denizgokalp/anaconda/lib/python3.6/site-packages/spyder/widgets/ipythonconsole/namespacebrowser.py", line 189, in _handle_execute_reply
self.handle_exec_method(msg)
File "/Users/denizgokalp/anaconda/lib/python3.6/site-packages/spyder/widgets/ipythonconsole/shell.py", line 248, in handle_exec_method
view = ast.literal_eval(data['text/plain'])
File "/Users/denizgokalp/anaconda/lib/python3.6/ast.py", line 85, in literal_eval
return _convert(node_or_string)
File "/Users/denizgokalp/anaconda/lib/python3.6/ast.py", line 66, in _convert
in zip(node.keys, node.values))
File "/Users/denizgokalp/anaconda/lib/python3.6/ast.py", line 65, in
return dict((_convert(k), _convert(v)) for k, v
File "/Users/denizgokalp/anaconda/lib/python3.6/ast.py", line 66, in _convert
in zip(node.keys, node.values))
File "/Users/denizgokalp/anaconda/lib/python3.6/ast.py", line 65, in
return dict((_convert(k), _convert(v)) for k, v
File "/Users/denizgokalp/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 0x1317f4208>

On 1 Aug 2017, at 00:01, Carlos Cordoba notifications@github.com wrote:

@mitchell5 https://github.com/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:

Put a line with print([data['text/plain']]) before line 311 in /anaconda/lib/python3.6/site-packages/spyder/widgets/ipythonconsole/shell.py.
Restart Spyder.
Go to the menu View > Panes > Internal console and copy the text printed there after you run 1+1 in a console.
Post the result here.
With that info we will be able to understand why the console is not returning the result Spyder expects.

—
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-319220483, or mute the thread https://github.com/notifications/unsubscribe-auth/AHHNavwirXxDM3-fwP_nvru_3HURB7f9ks5sTlysgaJpZM4OnX8k.

I'm closing this one because we don't a way to reproduce it, sorry.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hgijeon picture hgijeon  Â·  3Comments

hedeqing picture hedeqing  Â·  3Comments

JesterEE picture JesterEE  Â·  3Comments

danieltomasz picture danieltomasz  Â·  3Comments

cchu08 picture cchu08  Â·  3Comments