Skip to content

Kernel dies when using matplotlib to plot in notebook or save plot to image files #25530

Closed

Description

@zhu181

Environment data

  • VS Code version: 1.105.0
  • Jupyter Extension version (available under the Extensions sidebar): 2025.9.0
  • Python Extension version (available under the Extensions sidebar): 2025.16.0
  • OS (Windows | Mac | Linux distro) and version: Windows_NT x64 10.0.26120
  • Python and/or Anaconda version: 3.14.0
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): NA
  • Jupyter server running: Local

Expected behaviour

Expect the matplotlib can show the image and save the image to file.

Actual behaviour

The kernel died.

Steps to reproduce:

[NOTE: Self-contained, minimal reproducing code samples are extremely helpful and will expedite addressing your issue]

  1. Run the code.
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6])

This bug is very close to Issue microsoft/vscode-jupyter#9283. I have been experimenting with it.

I found that this bug seems to be related to the python environments(ms-python.vscode-python-envs) extension. The bug only occurs when the extension is enabled and activated(in the python.useEnvironmentsExtension setting), and when using an interpreter that is not a conda or a venv environment interpreter(such as the pixi environment in this case.).

The bug would also sometimes occur even when using a conda environment interpreter if "python-envs.defaultEnvManager": "ms-python.python:system" is set in the vscode workspace.

I also experiment with other matplotlib backends(agg, qtagg, tkagg and so on) and other python versions(3.12-3.14). These do not affect the outcomes.

However the bug would not happen in the jupyter notebook running in the browser, or using the jupyterhub extension(ms-toolsai.jupyter-hub) in vscode to connect to a running jupyter server.

Logs

Output for Jupyter in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Jupyter)

18:05:32.718 [warn] Failed to get activated env vars for d:\Academic\global_soil_moisture_pattern\sm_pattern_new\.pixi\envs\default\python.exe in 30178ms
18:05:32.782 [info] Process Execution: d:\Academic\global_soil_moisture_pattern\sm_pattern_new\.pixi\envs\default\python.exe -c "import ipykernel; print(ipykernel.__version__); print("5dc3a68c-e34e-4080-9c3e-2a532b2ccb4d"); print(ipykernel.__file__)"
18:05:32.846 [info] Process Execution: d:\Academic\global_soil_moisture_pattern\sm_pattern_new\.pixi\envs\default\python.exe -Xfrozen_modules=off -m ipykernel_launcher --f=~\AppData\Roaming\jupyter\runtime\kernel-v324d4ded8293c9240fc9812540c55c92d907ccd53.json
    > cwd: d:\test
18:05:34.131 [info] Restarted cd4f7a9a-e0ff-4c9e-aab2-971daca8e25d
18:05:34.711 [error] Disposing session as kernel process died ExitCode: 3228369023, Reason: traitlets.traitlets.TraitError

Activity

  1. added
    bugIssue identified by VS Code Team member as probable bug
    on Oct 12, 2025
  2. faultdiagnosistoolbox commented on Oct 14, 2025

    @faultdiagnosistoolbox

    Edit:
    After managing to dig deeper I found the problem I encountered and it was related to the update of ipykernel package to version 7.0.x. Downgrading to 6.30.1 resolves the issue.

    Sorry for my interruption of this topic.

    • VS Code version: 1.105.0
    • Jupyter Extension version (available under the Extensions sidebar): 2025.9.1
    • Python Extension version (available under the Extensions sidebar): 2025.16.0
    • OS: Mac
    • Python and/or Anaconda version: 3.12.09 and 3.13.3
    • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): venv
    • Jupyter server running: Local

    I think I have the same issue but I haven't been able to pinpoint exact versions of packages/extensions when it appeared.

    The minimal example above excites the problem for me. If I run the code interactively with a Jupyter session, it plots nicely inline. But if I activate a matplotlib backend the session crashes when I plot (have tried the tk backend).

    If I run directly in ipython; starts thebackend with %matplotlib and run the code it works as expected.

  3. DonJayamanne commented on Oct 15, 2025

    @DonJayamanne

    Thank you for the informaiton
    Zhu Liyang (@zhu181) Please could you try revering ipykernel as suggested.
    Erik Frisk (@faultdiagnosistoolbox) Do you run into similar isues outside vs code in Jupyter lab as well? If you do I suggest filing an issue upstream.

  4. faultdiagnosistoolbox commented on Oct 15, 2025

    @faultdiagnosistoolbox

    Yes, tried it now and I experience exactly the same behavior in Jupyter lab.

    I have reported the issue to ipykernel (I hope I got it in the right place in the issues system) ipython/ipykernel#1438 (comment)

  5. zhu181 commented on Oct 15, 2025

    @zhu181
    Author

    Don Jayamanne (@DonJayamanne) Reinstalling ipykernel doesn't fix this problem. Another minor issue is that the output panel doesn't always show kernel died reason. As the following shows

    21:36:59.565 [info] Kernel successfully started
    21:37:03.256 [error] Disposing session as kernel process died ExitCode: 3228369023, Reason: 
    

    Erik Frisk (@faultdiagnosistoolbox) I am not sure if the problem you encounter is related to this one, as I do not experience this behavior after your example in ipython/ipykernel#1438 (comment).

    Also, downgrading ipykernel to 6.30 doesn't fix this problem either, so I consider this to be a problem with the python environment extension. Perhaps I should file an issue there?

  6. zhu181 commented on Oct 15, 2025

    @zhu181
    Author

    Move the code to a .py file and find the same problem: matplotlib fail to plot image when python environment extension is enabled. This seems more like a problem with the python environment extension.

  7. DonJayamanne commented on Oct 15, 2025

    @DonJayamanne

    matplotlib fail to plot image when python environment extension is enabled. This seems more like a problem with the python environment extension.

    Zhu Liyang (@zhu181) Do you run into this issue if you disable/uninstall the Python Environment extension?

  8. zhu181 commented on Oct 16, 2025

    @zhu181
    Author

    No, this issue will not occur if the Python Environment extension is disabled or uninstalled.

    Edit:

    Also, as I said, this issue will not occur if I set python.useEnvironmentsExtension: false.

  9. added
    bugIssue identified by VS Code Team member as probable bug
    info-neededIssue requires more information from poster
    on Oct 16, 2025
  10. github-actions commented on Nov 15, 2025

    @github-actions

    Hey Karthik Nadig (@karthiknadig) Eleanor Boyd (@eleanorjboyd), this issue might need further attention.

    Zhu Liyang (@zhu181), you can help us out by closing this issue if the problem no longer exists, or adding more information.

  11. zhu181 commented on Nov 16, 2025

    @zhu181
    Author

    The problem can be solved by launching vscode in a terminal that has already activated the pixi environment, which suggests that the problem arises from that the pixi python environment is not properly activated by the python environment extension.

    I think that this might no longer be a serious issue. However, I would like to know that if it is possible to let user customize the process that the python environment extension activates the python environment or give more information about the process(the way that it is different from that when not enabling the extension) in docs?

    Should I close this issue Eleanor Boyd (@eleanorjboyd) Karthik Nadig (@karthiknadig) ?

  12. eleanorjboyd commented on Nov 18, 2025

    @eleanorjboyd
    Member

    does using this specific extension that integrates with the Python Environments Extension for Pixi help if you enable this and use your pixi environment managed by this one? https://github.com/renan-r-santos/pixi-code/tree/main/src

  13. zhu181 commented on Nov 20, 2025

    @zhu181
    Author

    It (https://github.com/renan-r-santos/pixi-code/tree/main/src, renan-r-santos.pixi-code) helps in my case. Thanks very much for the information!

  14. eleanorjboyd commented on Nov 20, 2025

    @eleanorjboyd
    Member
  15. added
    verifiedVerification succeeded
    needs PRReady to be worked on
    and removed
    triage-neededNeeds assignment to the proper sub-team
    on Dec 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugIssue identified by VS Code Team member as probable bugneeds PRReady to be worked onverifiedVerification succeeded

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions