Skip to content

Using a Jupyter Notebook with Pixi and VS Code #5099

Closed

Description

@Omnistic

Problem description

I am aware of #411, and I am not a software developer. But I can't get a Jupyter Notebook to work in my VS Code with the Pixi Extension. My workflow is as follows (in VS Code):

The kernel seems to be right in the Notebook, it is: .pixi\envs\default\python.exe, and if I just have print('test') in my notebook cell it works. But as soon as I import anything the kernel crashes. In the VS Code OUTPUT, I get a warning that seems relevant:
17:48:39.059 [warn] Failed to get activated env vars for ~\Documents\GitHub\my_folder\.pixi\envs\default\python.exe in 30028ms

I am not sure what to report regarding the crash (or even how to report it), and I am using Windows in case it matters.

Has anybody else had this problem? Is here the right place to ask? Please consider that I am not a software developer and I don't understand a lot of the jargon that is used here.

Thanks for any help you can provide.

Omni

Activity

  1. bollwyvl commented on Dec 10, 2025

    @bollwyvl
    Contributor

    For a single environment, several approaches to starting code (or any other
    $PATH-aware tool) will generally set up all the environment variables properly, e.g.

    Given code is not running (if it is, none of these will have any effect):

    • activate the shell

      pixi shell
      code .
    • ...or run code directly (returns control immediately):

      pixi run code .
    • ... or make task

      # pixi.toml
      [tasks]
      start-code = "code ."

      ...then

      pixi r start-code

    The latter is handy if there is a package-under-development involved, as it could do any pre-flight steps.

    For multiple envs, things get a bit more challenging. I've at least once done some out-of-band scripting to:

    • plan to launch the tool from a specific environment (e.g. dev)
    • find all
      • .pixi/envs/{env}/share/jupyter/kernels/{name}/kernel.json
    • munge all of the kernels into
      • .pixi/envs/default/share/jupyter/kernels/pixi-{env}-{name}/kernel.json
      • update all of the argv:
        • from
          {
            "argv": [
              "python",
              "-m",
              "ipykernel_launcher",
              "-f",
              "{connection_file}"
            ],
            "display_name": "Python 3 (ipykernel)",
            "language": "python",
            "metadata": {
              "debugger": true
            }
          }
        • to
          {
            "argv": [
              "pixi",
              "run",
              "--environment={env}",
              "python",
              "-m",
              "ipykernel_launcher",
              "-f",
              "{connection_file}"
            ],
            "display_name": "({env}) Python 3 (ipykernel)",
            "language": "python",
            "metadata": {
              "debugger": true
            }
          }
    • launch the tool

    It's possible this could all be done with some clever xargs | jq invocation,
    but i generally fall back to python.

    This approach has the (usually beneficial) side-effect of restart-and-run-all potentially
    re-locking/rebuilding an environment. However, this can get very annoying if there is any
    "deep magic" at play, such as a pixi-managed python package which also sees the
    file-being-edited as something that should invalidate the lock file.

  2. Omnistic commented on Dec 11, 2025

    @Omnistic
    Author

    @bollwyvl thank you for your answer. It is much appreciated.

    However, I don't really understand it.

    I have a single environment, and still I tried the various commands that you sent in VS Code terminal to no avail.

    I am attaching a screenshot of what I am trying to do, in case it might be helpful.

    Image

    And here is the log from the screenshot (for copy/paste if necessary):

    15:05:46.415 [warn] Failed to get activated env vars for ~\Documents\GitHub\trying_pixi_vscode_notebook\.pixi\envs\default\python.exe in 30075ms
    15:05:46.420 [info] Process Execution: ~\Documents\GitHub\trying_pixi_vscode_notebook\.pixi\envs\default\python.exe -c "import site;print("USER_BASE_VALUE");print(site.USER_SITE);print("USER_BASE_VALUE");"
    15:05:46.420 [warn] Failed to get activated env vars for ~\Documents\GitHub\trying_pixi_vscode_notebook\.pixi\envs\default\python.exe in 30071ms
    15:05:46.445 [info] Process Execution: ~\Documents\GitHub\trying_pixi_vscode_notebook\.pixi\envs\default\python.exe -m pip list
    15:05:46.447 [info] Process Execution: ~\Documents\GitHub\trying_pixi_vscode_notebook\.pixi\envs\default\python.exe -c "import ipykernel; print(ipykernel.__version__); print("5dc3a68c-e34e-4080-9c3e-2a532b2ccb4d"); print(ipykernel.__file__)"
    15:05:46.450 [info] Process Execution: ~\Documents\GitHub\trying_pixi_vscode_notebook\.pixi\envs\default\python.exe ~\.vscode\extensions\ms-toolsai.jupyter-2025.9.1-win32-x64\pythonFiles\vscode_datascience_helpers\kernel_interrupt_daemon.py --ppid 32624
        > cwd: ~\.vscode\extensions\ms-toolsai.jupyter-2025.9.1-win32-x64\pythonFiles\vscode_datascience_helpers
    15:05:46.505 [info] Process Execution: ~\Documents\GitHub\trying_pixi_vscode_notebook\.pixi\envs\default\python.exe -m ipykernel_launcher --f=~\AppData\Roaming\jupyter\runtime\kernel-v3c1244e16bf3a65418c9825c6afb2855b4996da10.json
        > cwd: ~\Documents\GitHub\trying_pixi_vscode_notebook
    15:05:47.161 [info] Kernel successfully started
    15:05:47.229 [error] Disposing session as kernel process died ExitCode: 3228369023, Reason: 
    15:06:17.185 [warn] Failed to get activated env vars for ~\Documents\GitHub\trying_pixi_vscode_notebook\.pixi\envs\default\python.exe in 30022ms
    15:06:17.189 [info] Process Execution: ~\Documents\GitHub\trying_pixi_vscode_notebook\.pixi\envs\default\python.exe ~\.vscode\extensions\ms-toolsai.jupyter-2025.9.1-win32-x64\pythonFiles\printJupyterDataDir.py
    

    I would like to have my notebook in VS Code, because that's an environment I am familiar with. And ever since I tried it, I fell in love with Pixi, so I'd also like to have that.

    Would you mind explaining to me in Layman's term how I am supposed to set this up?

    So far, I went back to a Conda environment and a notebook in VS Code, and that works. But it would be better with Pixi of course.

    Thank you for your help and take care,

    Omni

  3. bollwyvl commented on Dec 11, 2025

    @bollwyvl
    Contributor

    The simplest windows path:

    • close vscode
    • start a boring, non-magic, broken-for-the-same-way-for-30-years command prompt
      • from the run menu, start cmd.exe
    • navigate to the working directory where pixi.toml is located
      • cd c:/Documents/GitHub/trying_pixi_vscode_notebook
    • start code from pixi
      • pixi run code .
      • if this fails to find pixi.exe, it might need to use the concrete location, e.g.
        • c:\Program Files\pixi\pixi.exe run code .

    It may also be that vscode_datascience_helpers relies on sniffing magic values, or is otherwise not good. One could try disabling that, and anything else mentioned in the logs, at least initially, and then re-add them to bisect what is causing the error.

  4. Omnistic commented on Dec 11, 2025

    @Omnistic
    Author

    It worked right away. I had no idea I could start VS Code from PIXI. I guess this was a stupid question, but thank you so much for taking the time to answer. I am very grateful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions