When does Spyder invalidate its completion cache after a package upgrade?
0 reputation · 27 Sept 2022, 23:57 UTC
0 reputation · 27 Sept 2022, 23:57 UTC
Spyder’s Variable Explorer snapshots the current namespace, and its code completion relies on the Language Server Protocol. When a package in the environment is upgraded or a module on disk is modified, the IDE may still display old symbols or values until a manual refresh occurs.
The documentation does not state whether a simple kernel restart clears these caches or if a full IDE restart is required. This ambiguity leads users to guess whether they need to restart the console, the editor, or both after an environment change.
33775 reputation · 28 Sept 2022, 10:58 UTC
Spyder’s code‑completion cache is held by the language server that runs in a separate process (usually jedi or pylsp). The cache is not tied to the kernel itself, so a kernel restart alone does not clear it. The cache is invalidated only when the language server process is restarted, which Spyder does automatically when you select "Kernel → Restart" or when you explicitly choose "Restart Language Server" from the Tools → Preferences → Python Interpreter dialog. In practice, a kernel restart is enough because Spyder sends a request to the language server to restart it as part of the kernel restart workflow.
pip install --upgrade mypkg) in the environment that Spyder is using.Kernel → Restart (or press Ctrl+Shift+F5).restart command to the language server.Restarting only the console (e.g., via Ctrl+Shift+F5 on the console tab) is sufficient; you do not need to close and reopen Spyder itself.
Spyder’s Variable Explorer takes a snapshot of the namespace when the kernel starts. If you edit a module file on disk, the explorer does not automatically refresh. You must either:
Most language servers used by Spyder do not monitor the file system for changes. They only re‑index when they receive a restart message or when the user explicitly triggers “Restart Language Server.” Therefore, after editing a module file, you need to either save the file and then restart the language server, or restart the kernel to get the updated symbols in completions.
Kernel → Restart and try the completion again. The updated symbols should now appear.Check which language server is active:
Tools → Preferences → Python Interpreter → Language Server
If you are using pylsp with the pylsp-mypy plugin, you may need to enable the pylsp-restart command manually. If the interpreter path has changed (e.g., after activating a different conda environment), you must restart Spyder entirely to pick up the new interpreter.
Could you let us know which language server Spyder is using in your setup? That will help confirm the exact restart behavior for your environment.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.