Spyder: Cannot open objects in variable explorer

Created on 4 Feb 2020  路  13Comments  路  Source: spyder-ide/spyder

Description

What steps will reproduce the problem?

  1. Define a class in another file
  2. In a new file import the class file
  3. create an object with that class

  4. run the code. The code runs fine

  5. try to explore the newly created object and get the following message

Spyder was unable to retrieve the value of this variable from the console.

The error message was:
'tuple' object has no attribute 'raise_error'

  1. The object is not a tuple. Indeed the value is " XXX object of YYYY module"

This is not related only to a single script. As I tried to create mock files and scripts but the problem persists.

Regards.

Versions

  • Spyder version: 4.0.1
  • Python version: 3.7.4
  • Qt version: 5.9.6
  • PyQt5 version: 5.9.2
  • Operating System: Linux 4.15.0-76-generic

Dependencies

atomicwrites >=1.2.0         :  1.3.0 (OK)
chardet >=2.0.0              :  3.0.4 (OK)
cloudpickle >=0.5.0          :  1.2.2 (OK)
diff_match_patch >=20181111  :  20181111 (OK)
intervaltree                 :  None (OK)
IPython >=4.0                :  7.11.1 (OK)
jedi =0.14.1                 :  0.14.1 (OK)
keyring                      :  None (OK)
nbconvert >=4.0              :  5.6.1 (OK)
numpydoc >=0.6.0             :  0.9.2 (OK)
pexpect >=4.4.0              :  4.8.0 (OK)
pickleshare >=0.4            :  0.7.5 (OK)
psutil >=0.3                 :  5.6.7 (OK)
pygments >=2.0               :  2.5.2 (OK)
pylint >=0.25                :  2.4.4 (OK)
pyls >=0.31.2;<0.32.0        :  0.31.2 (OK)
xdg >=0.26                   :  0.26 (OK)
zmq >=17                     :  18.1.0 (OK)
qdarkstyle >=2.7             :  2.7 (OK)
qtawesome >=0.5.7            :  0.6.0 (OK)
qtconsole >=4.6.0            :  4.6.0 (OK)
qtpy >=1.5.0                 :  1.9.0 (OK)
rtree >=0.8.3                :  0.8.3 (OK)
sphinx >=0.6.6               :  2.3.1 (OK)
spyder_kernels >=1.8.1;<2.0.0:  1.8.1 (OK)
watchdog                     :  None (OK)
cython >=0.21                :  0.29.14 (OK)
matplotlib >=2.0.0           :  3.1.1 (OK)
numpy >=1.7                  :  1.18.1 (OK)
pandas >=0.13.1              :  0.25.3 (OK)
scipy >=0.17.0               :  1.3.2 (OK)
sympy >=0.7.3                :  1.5.1 (OK)
IPython Console Bug v4.1.0

Most helpful comment

@PedroMat8 You should wait for the next release of Spyder, or installing it from source.
The fix won't let you open the objects in the variable explorer as spyder won't know where to look for class_folder/init.py (because you modify the path manually.)
This is a limitation of pickle so there is nothing we can do now. I would encourage you to organise your code in a way that doesn't require to manually change the path.

All 13 comments

Please provide a simple and reproducible example we can use in our side to debug this problem.

Please see attached the files to reproduce the error in spyder.The error occurs when running the script call_class.py.聽Below I report the code tree:debug/class_folder/pore_distribution.pydebug/class_folder/__init__.pydebug/main_folder/call_class.py聽I hope this will answer your question.Please let me know if you need further information聽聽Sent from Mail for Windows 10聽From: Carlos CordobaSent: 04 February 2020 16:32To: spyder-ide/spyderCc: Matteo Pedrotti; AuthorSubject: Re: [spyder-ide/spyder] Cannot open objects in variable explorer (#11471)聽Please provide a simple and reproducible example we can use in our side to debug this problem.鈥擸ou are receiving this because you authored the thread.Reply to this email directly, view it on GitHub, or unsubscribe.聽

@PedroMat8 attached files do not work on emails you need to come to the actual issue an upload it

https://github.com/spyder-ide/spyder/issues/11471

Thanks

Please see attached the files to reproduce the error in spyder.
The error occurs when running the script call_class.py.

Below I report the code tree:

  • debug/class_folder/pore_distribution.py
  • debug/class_folder/__init__.py
  • debug/main_folder/call_class.py

debug.zip

@dalthviz, please try to reproduce this one.

@ccordoba12 I was able to reproduce this. Seems like an error when trying to retrieve the value from the kernel:

  File "C:\Users\Daniel\Documents\Spyder\spyder\spyder\plugins\variableexplorer\widgets\collectionsdelegate.py", line 109, in createEditor
    value = self.get_value(index)
  File "C:\Users\Daniel\Documents\Spyder\spyder\spyder\plugins\variableexplorer\widgets\collectionseditor.py", line 1380, in get_value
    return self.parent().get_value(name)
  File "C:\Users\Daniel\Documents\Spyder\spyder\spyder\plugins\variableexplorer\widgets\collectionseditor.py", line 1433, in get_value
    value = self.shellwidget.get_value(name)
  File "C:\Users\Daniel\Documents\Spyder\spyder\spyder\plugins\ipythonconsole\widgets\namespacebrowser.py", line 99, in get_value
    timeout=CALL_KERNEL_TIMEOUT).get_value(name)
  File "C:\Users\Daniel\Anaconda3\envs\spyder4\lib\site-packages\spyder_kernels\comms\commbase.py", line 542, in __call__
    call_dict, call_data, self._comm_id)
  File "C:\Users\Daniel\Documents\Spyder\spyder\spyder\plugins\ipythonconsole\comms\kernelcomm.py", line 132, in _get_call_return_value
    call_dict, call_data, comm_id)
  File "C:\Users\Daniel\Anaconda3\envs\spyder4\lib\site-packages\spyder_kernels\comms\commbase.py", line 420, in _get_call_return_value
    return self._sync_error(reply['value'])
  File "C:\Users\Daniel\Anaconda3\envs\spyder4\lib\site-packages\spyder_kernels\comms\commbase.py", line 480, in _sync_error
    error_wrapper.raise_error()
AttributeError: 'tuple' object has no attribute 'raise_error'

Some ideas here @impact27 ?

Testing a little bit seems like the error that the kernel is trying to handle is the tuple (ModuleNotFoundError("No module named 'class_folder'"), [])

Checking the structure of the folder send by @PedroMat8 a way to prevent a ModuleNotFoundError is to make the main module (the entry point of the execution) to be at the level of the directory of the module that contains the classes needed (although a review of relative and absolute imports could help too). Something like the following:

Instead of

.../main_folder/
             .../call_class.py (module that is being run)
.../class_folder/
            .../pore_distribution.py

Use a directory structure like

.../main_folder/
             .../call_class.py (module that is being run)
             .../class_folder/
                       .../pore_distribution.py

Anyhow the handling of the error in the kernel needs a review of course :)

Thanks @dalthviz for digging deeper into this one! Do you understand why a tuple is generated instead of a single ModuleNotFoundError when running get_value in this case?

I'm unsure but will check @ccordoba12 :+1:

@ccordoba12 seems like in spyder-kernels 'blocking' calls are handle with _handle_remote_call_reply where an empty list [] is used to create a tuple with the incoming exception. Also, seems like the excepted exception object needs to have the raise_error attribute that the CommsErrorWrapper defines. However, I'm not totally sure how the wrapper is applied or why the exception it's being used along with the empty list [] to generate a tuple. Maybe @impact27 could have an idea of what we can do here?

Hi,聽I see the problem has been fixed.What I am supposed to do in order to update it on my computer?聽Sorry for the dull question, but it is my first time.聽Thanks聽聽From: Carlos CordobaSent: 18 February 2020 04:16To: spyder-ide/spyderCc: Matteo Pedrotti; MentionSubject: Re: [spyder-ide/spyder] Cannot open objects in variable explorer (#11471)聽Closed #11471 via a16b482.鈥擸ou are receiving this because you were mentioned.Reply to this email directly, view it on GitHub, or unsubscribe.聽

@PedroMat8 You should wait for the next release of Spyder, or installing it from source.
The fix won't let you open the objects in the variable explorer as spyder won't know where to look for class_folder/init.py (because you modify the path manually.)
This is a limitation of pickle so there is nothing we can do now. I would encourage you to organise your code in a way that doesn't require to manually change the path.

Was this page helpful?
0 / 5 - 0 ratings