Spyder was unable to retrieve the value depends on how module is imported
See original GitHub issueIssue 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
(orpip
, 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)
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:31 (6 by maintainers)
Top GitHub 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 have a similar configuration as guido: base environment with
Spyder 5.1.5
and other environments withspypder-kernels 2.1.3
. All environments withpython 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.