question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

KeyError self.editor_ids[self.current_editor]

See original GitHub issue

@bnavigator , it actually looks like your first error is

editor_id = self.editor_ids[self.current_editor]
KeyError: <spyder.plugins.outlineexplorer.editor.OutlineExplorerProxyEditor object at 0x7f0efd7ea280>

which means that self.current_editor returns an OutlineExplorerProxyEditor object instead of a string object. Could this be related to PyQt5 >= 5.13?

_Originally posted by @mrclary in https://github.com/spyder-ide/spyder/issues/14803#issuecomment-846075484_

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
mrclarycommented, May 21, 2021

I inserted some print statements at line 412 and ran bootstrap from a pyenv environment with PyQt5=5.15.4

    @Slot()
    def go_to_cursor_position(self):
        if self.current_editor is not None:
            print(f'TEST: self.current_editor = {self.current_editor}')
            print(f'TEST: self.editor_ids = {self.editor_ids}')
            editor_id = self.editor_ids[self.current_editor]

with the following results

(spy-build) >> python bootstrap.py
Executing Spyder from source checkout
*. Patched sys.path with /Users/rclary/Documents/Python/spyder
*. Patched sys.path with /Users/rclary/Documents/Python/spyder/external-deps/spyder-kernels
*. Patched sys.path with /Users/rclary/Documents/Python/spyder/external-deps/qdarkstyle
*. Patched sys.path with /Users/rclary/Documents/Python/spyder/external-deps/python-language-server
*. Removing previous PyLS local installation.
*. Installing PyLS locally
*. Declaring completion providers
*. PyQt5 is detected, selecting
*. Imported Spyder 5.1.0.dev0 - Revision 65294a8b8, Branch: constrain-watchdog
    [Python 3.9.4 64bits, Qt 5.15.2, PyQt5 5.15.4 on Darwin]
*. Running Spyder
Bootstrap completed in 00:00:01.2356
No QCoreApplication instance found. Application patches not applied. You have to call load_stylesheet function after instantiation of QApplication to take effect. 
The available OpenGL surface format was either not version 3.2 or higher or not a Core Profile.
Chromium on macOS will fall back to software rendering in this case.
Hardware acceleration and features such as WebGL will not be available.
Populating font family aliases took 177 ms. Replace uses of missing font family "Quattrocento Sans" with one that exists to avoid this cost. 
TEST: self.current_editor = <spyder.plugins.outlineexplorer.editor.OutlineExplorerProxyEditor object at 0x158df7b80>
TEST: self.editor_ids = {<spyder.plugins.outlineexplorer.editor.OutlineExplorerProxyEditor object at 0x158df7b80>: 5782023904}

That was upon startup. I was incorrect about my assumption that it was looking for a string object. It appears that the dictionary is using unique objects as keys. Nevertheless, upon switching projects once, no prints are encountered, so go_to_cursor_position is not accessed. Upon switching back to the orignal project, again no prints are encountered, but I get the error reported in #14803

ERROR:fsevents:Unhandled exception in FSEventsEmitter
Traceback (most recent call last):
  File "/Users/rclary/.pyenv/versions/3.9.4/envs/spy-build/lib/python3.9/site-packages/watchdog/observers/fsevents.py", line 310, in run
    _fsevents.add_watch(self, self.watch, self.events_callback, self.pathnames)
RuntimeError: Cannot add watch <ObservedWatch: path=/Users/rclary/Documents/Python/c2w_psp, is_recursive=True> - it is already scheduled

Can you run with some print statements to see under what circumstances there is a KeyError?

0reactions
bnavigatorcommented, May 28, 2021

I cannot reproduce the error anymore. None of the listed direct dependencies changed from https://github.com/spyder-ide/spyder/issues/15668#issuecomment-846589975 to now.

Notable changes which could be related:

  • Python packages:
    • PyQt5.sip 12.8.1 -> 12.9.0
    • libcst 0.3.17 -> 0.3.19
    • fsspec 0.8.5 -> 2021.5.0
  • Some recompiled system libraries:
    • libX11 and libX11-xcb
    • nothing Qt related.

Well, I would definitely recommend creating a virtual environment from which to run Spyder.

That currently pulls in 538 MB of unnecessary, duplicate and outdated stuff. Most notably a complete set of precompiled Qt libraries, which don’t work well in parallel with an already loaded system Qt.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python KeyError Exceptions and How to Handle Them
In this tutorial, you'll learn how to handle Python KeyError exceptions. They are often caused by a bad key lookup in a dictionary,...
Read more >
How to Fix KeyError Exceptions in Python - Rollbar
The Python KeyError is an exception that occurs when an attempt is made to access an item in a dictionary that does not...
Read more >
Key Error Running Python Script (Using Atom) - Stack Overflow
I'm using Atom text editor plus the Hydrogen module to run said code. I am getting KeyError: '203' when I run the following...
Read more >
What is KeyError in Python? Dictionary and Handling Them
This article will provide you with a detailed and comprehensive knowledge of how to resolve KeyError in Python in Dictionary.
Read more >
KeyError Pandas – How To Fix - Data Independent
Pandas KeyError - This annoying error means that Pandas can not find your ... _getitem_multilevel(key) -> 2899 indexer = self.columns.get_loc(key) 2900 if ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found