spyder: Spyder was unable to retrieve the value depends on how module is imported

Issue Report Checklist

  • Searched the issues page for similar reports
  • Read the relevant sections of the Spyder Troubleshooting Guide and followed its advice
  • Reproduced the issue after updating with conda update spyder (or pip, if not using Anaconda)
  • Could not reproduce inside jupyter qtconsole (if console-related)
  • Tried basic troubleshooting (if a bug/error)
    • Restarted Spyder
    • Reset preferences with spyder --reset
    • Reinstalled the latest version of Anaconda
    • Tried the other applicable steps from the Troubleshooting Guide
  • Completed the Problem Description, Steps to Reproduce and Version sections below

Problem Description

In the variable explorer I get the error message “Spyder was unable to retrieve the value of this variable from the console.” when double clicking on a class instance, but only when the module containing the class is imported in certain ways. When imported in other ways the same class will display as expected.

Furthermore, there seems to be an oddity where the error will show for a class when first run, yet when the same script is run again the variable will sometimes display as expected.

Specifically this seems to occur if a module is imported from outside the directory tree in which the main python script is located after adding a folder to the path using sys.path.append().

I’ve tested this on Windows on an Anaconda installation and on Linux using a miniconda installation and get exactly the same behaviour in both situations.

The error message shown in the error popup is " The Error message was: An error occurred, see the console…" however there is no error or traceback in the console.

What steps reproduce the problem?

Consider the following folder structure (I’ve attached a zip file with these file included): spyder_import.zip

/home/tom/spyder_import
|--testclass_folder
|  |--testclass_outside.py
|--testscript_folder
|  |--testscript.py
|  |--testclass_subfolder
|     |--testclass_inside.py

Where testclass_outside.py and testclass_inside.py contain identical class definitions (except varying names):

testclass_inside.py:

class tc_inside():
    def __init__(self):
        self.var = 123
    
    def printvar(self):
        print(self.var)

testclass_outside.py:

class tc_outside():
    def __init__(self):
        self.var = 123
    
    def printvar(self):
        print(self.var)

testscript.py imports these two classes in three different ways:

import sys
sys.path.append(r"/home/tom/spyder_import")

from testclass_subfolder import testclass_inside
from testclass_folder import testclass_outside
import testclass_folder.testclass_outside as testclass_outside_direct

tc_inside_instance = testclass_inside.tc_inside()
tc_outside_instance = testclass_outside.tc_outside()
tc_outside_direct_instance = testclass_outside_direct.tc_outside()

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

When running testscript.py in Spyder, I expect to be able to view all three class instances in the object explorer.

What I actually see is the first time I run the script only tc_inside_instance shows properly in the object explorer, the other two classes produce the “Spyder was unable to retrieve the value of this variable from the console.” error. If I immediately run the script again tc_outside_instance will sometimes show, but sometimes not. tc_outside_direct_instance will never show properly

Paste Traceback/Error Below (if applicable)

There is no error or traceback in the console

Versions

  • Spyder version: 5.0.3
  • Python version: 3.9.1
  • Qt version: 5.9.7
  • PyQt version: 5.9.2
  • Operating System name/version: Ubuntu 20.10 / Windows 10

Dependencies

Mandatory:

atomicwrites >=1.2.0 : 1.4.0 (OK) chardet >=2.0.0 : 4.0.0 (OK) cloudpickle >=0.5.0 : 1.6.0 (OK) cookiecutter >=1.6.0 : 1.7.2 (OK) diff_match_patch >=20181111 : 20200713 (OK) intervaltree >=3.0.2 : 3.1.0 (OK) IPython >=7.6.0 : 7.22.0 (OK) jedi =0.17.2 : 0.17.2 (OK) jsonschema >=3.2.0 : 3.2.0 (OK) keyring >=17.0.0 : 23.0.1 (OK) nbconvert >=4.0 : 6.0.7 (OK) numpydoc >=0.6.0 : 1.1.0 (OK) parso =0.7.0 : 0.7.0 (OK) pexpect >=4.4.0 : 4.8.0 (OK) pickleshare >=0.4 : 0.7.5 (OK) psutil >=5.3 : 5.8.0 (OK) pygments >=2.0 : 2.9.0 (OK) pylint >=1.0 : 2.8.3 (OK) pyls >=0.36.2;<1.0.0 : 0.36.2 (OK) pyls_black >=0.4.6 : 0.4.6 (OK) pyls_spyder >=0.3.2;<0.4.0 : 0.3.2 (OK) qdarkstyle =3.0.2 : 3.0.2 (OK) qstylizer >=0.1.10 : 0.1.10 (OK) qtawesome >=1.0.2 : 1.0.2 (OK) qtconsole >=5.1.0 : 5.1.0 (OK) qtpy >=1.5.0 : 1.9.0 (OK) rtree >=0.9.7 : 0.9.7 (OK) setuptools >=39.0.0 : 52.0.0.post20210125 (OK) sphinx >=0.6.6 : 4.0.1 (OK) spyder_kernels >=2.0.3;<2.1.0 : 2.0.3 (OK) textdistance >=4.2.0 : 4.2.1 (OK) three_merge >=0.1.1 : 0.1.1 (OK) watchdog >=0.10.3;<2.0.0 : 1.0.2 (OK) xdg >=0.26 : 0.27 (OK) zmq >=17 : 20.0.0 (OK)

Optional:

cython >=0.21 : None (NOK) matplotlib >=2.0.0 : None (NOK) numpy >=1.7 : 1.20.2 (OK) pandas >=1.1.1 : 1.2.3 (OK) scipy >=0.17.0 : None (NOK) sympy >=0.7.3 : None (NOK)

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 1
  • Comments: 34 (6 by maintainers)

Most upvoted comments

I had the same problem but found a work-around. For me the problem was that I has Spyder installed in the base environment of Anaconda but was using a python interpreter from a different environment. When I instead installed and launched Spyder from the same environment as the interpreter I was using, the problem went away.

I don’t even have pandas in my base environment, is that important that you have certain packages in your base environment where spyder is installed?

However I solved the problem by completely installing spyder in my working environment and not only the spyder-kernels.

Thanks lwbaqueros, your suggestion of downgardging pandas to 1.3.5 worked for me as well.

I had : Spyder 5.2.2 spyder-kernels 2.2.1 python 3.8.12 pandas 1.4.1

which was leading me to the following error message : image

I have a similar configuration as guido: base environment with Spyder 5.1.5 and other environments with spypder-kernels 2.1.3. All environments with python 3.9.7. Spyder (using the Python interpreter from the working environment) could not retrieve the value of a pandas dataframe.

My working environment had pandas 1.4.1. When I downgraded it to version 1.3.5, the Spyder variable explorer worked again.

I uninstalled spyder kernels from my environment and installed complete new spyder with “conda install spyder”. I use miniconda so conda equals conda-forge here. Now the variable explorer works again and I can jump to code lines over the traceback again. I noticed that geopandas got downgraded to 0.9… maybe that has influence.

Iam still confused that guides recommend my initial behaviour:

https://github.com/spyder-ide/spyder/wiki/Working-with-packages-and-environments-in-Spyder

Install just the spyder-kernels package into the myenv environment, and set your Python interpreter path in Spyder's Preferences to point to myenv's Python executable (see the [final section](https://github.com/spyder-ide/spyder/wiki/Working-with-packages-and-environments-in-Spyder#the-modular-approach). This requires one more initial step, but requires less maintenance in the long run and avoids duplicate Spyder installs.

Yeah, I have miniconda installed and spyder in the base environment, in my other environments I installed the spypder-kernels, like it is recommended for environment use. I consider moving to pycharm… each month I face a problem in spyder, the debugger needs hours to start if I wanna debug plotly dash, the variable explorer isnt working correcty, pycharrm doesn’t have these problems, however in my heart I’m a spyderino. I’m very sad.

Hello,

Yes, see below. I presume “An error occurred, see the console…” is a generic catch-all error message, but in this case it’s confusing because there is no output in the console. I have on occasions seen more descriptive messages here when Spyder cannot show the variable, such as when the variable is too big, so if it’s possible to detect that the error is caused by Spyder not being able to find the class definition then a message such as “Cannot find class definition file, ensure it is in the Spyder PYTHONPATH” would be useful.

Screenshot from 2021-07-13 03-01-30

Hello team, I was encountering this problem using Python 3.10 virtual environment in Win10. I solved activating the virtual environment and installing spyder-kernels 2.4.0 and spyder 5.4.0 inside the venv , Starting spyder from the venv console with these configurations solved the problem.

Ran into this issue the other day on Ubuntu 22.04, on the base env I uninstalled anaconda spyder and installed the pip version 5.4.0 then installed pandas 1.5.2 because I noticed pandas was not installed on base. Then on a second environment I use as the interpreter I installed pandas 1.5.2 and that seems to work now displaying the dataframes.

@mochsner, the variable explorer should work with external environments in the same way as for the one in which Spyder is installed. Please open a new issue about your problem and provide a step by step description on how to reproduce it.

So this prompted me to loop back, and this is limited to DataFrame in my case, which makes sense if pandas may not be installed on the spyder-cf conda env I’m running spyder from.

So, for every variable type I want to view in the spyder variable explorer, I guess I’ll just need to install the library the type derives from in spyder-cf env? If this is the case (would love confirmation), I’d be happy to check places in documentation this could be missing, and add a more detailed issue to ensure it’s documented across the board.

@mochsner, the variable explorer should work with external environments in the same way as for the one in which Spyder is installed. Please open a new issue about your problem and provide a step by step description on how to reproduce it.