51

I am running jupyter notebook in vscode. But when I try to run the following cell of code I got error.

import os
from torch.utils.data import DataLoader
from torchvision.datasets import ImageFolder
import torchvision.transforms as tt
import torch
import torch.nn as nn
import cv2
from tqdm.notebook import tqdm
import torch.nn.functional as F
from torchvision.utils import save_image
from torchvision.utils import make_grid
import matplotlib.pyplot as plt
%matplotlib inline

The error is

Error loading preloads:
Could not find renderer

I tried but could not find its solution on the internet. How can I resolve this issue?

doc
  • 828
  • 2
  • 6
  • 18

11 Answers11

79

In my case, I had Jupyter notebook extension installed. So, I did ctrl+shift+P and did Reload window; resolved!

In case you just don't see the bar without any error: disable Jupyter notebook renderers extension, test, and then re-enable it

Sadra
  • 2,480
  • 2
  • 20
  • 32
27

I am having the same issue with the latest release of the VS code Jupyer extension. The fix for now is to just go to the Jupyter extension tab, then the button that says "Uninstall," click the down arrow and hit "Install Another Version" and just install the version from > 1 mo ago and it should work fine. Hopefully they'll resolve this issue in the latest version soon.

Brandon Brown
  • 886
  • 1
  • 9
  • 13
  • 3
    Just in case anyone is not sure which version that is, it's: v2021.8.1195043623 – J.Warren Sep 02 '21 at 07:37
  • 1
    That's weird: I tried ensure only most update version was installed which didn't work. Then downgraded to v2021.8.1195043623 which worked. VSCode has just auto-updated to the latest version again and it still works... – J.Warren Sep 02 '21 at 07:48
  • 1
    in my case the package ms-toolsai.jupyter-renderers was missing – Grzegorz Głowacki Oct 08 '21 at 12:26
  • 2
    Installing the last v2021.8 VS Code Jupyter extension worked for me. Don't install v2021.9 – Thomas Tiotto Oct 25 '21 at 07:30
  • 2
    This is still an issue in February 2022. Same solution worked. I just randomly chose a version from a few months back and it resolved the issue. – DChaps Feb 07 '22 at 20:34
9
  1. Install/reinstall Jupyter Notebook Renderers Extension

  2. Reload Window

    Open the Command Palette (Ctrl + Shift + P)
    Then type: Reload Window

If this still doesn't work, make sure plot presentation is set to:

image/png
Jupyter Notebook Renderer (ms-toolsai.jupyter-renderers)

Change Presentation

Select Renderer

You should now be able to generate a plot in the interactive window. Hovering over the plot will give options to expand or save.

To get a better looking plot when zoomed in enable the "Jupyter: Generate SVGPlots" setting in the "Jupyter" extension and reload the window again. Then change the plot presentation to:

image/svg+xml
Jupyter Notebook Renderer (ms-toolsai.jupyter-renderers)
4

From the github issue: Renderer extension not being installed -- causes some packages not to work, like plotly. It should have been fixed in new release because the issue was closed on 14 Jan.

Run this code and see if the question goes away:

import plotly.io as pio
pio.renderers.default = 'iframe_connected'

OR

You may try to uninstall Jupyter extension completely by deleting its packages in the folder \...\.vscode\extensions\ms-toolsai.jupyter then reinstall the latest version.

Molly Wang-MSFT
  • 7,943
  • 2
  • 9
  • 22
4

Install extension Jupyter Notebook Renderers and update your VS code to the latest version.

Jobayer Ahmmed
  • 1,856
  • 3
  • 16
  • 20
  • 7
    In my case the solution was in fact to disable the "Jupyter Notebook Renderers" extension – grafo Dec 01 '21 at 14:18
2

enter image description here

When you install the Jupyter extension, Jupyter Notebook Renderers are also installed because it's included in the extension pack. This extension is causing this error so remove the extension from the Jupyter extension details and try running the block again.

Jeff
  • 524
  • 5
  • 17
2

just disable the "jupyter notebook renderers" in the extension section and then Reload it. Lastly, enable it and you're good to go.

tomas
  • 31
  • 2
0

If the mentioned solutions do not work try the followings as well:

  • check if you have all packages installed, for me the problem was that one package was not installed and I saw the same error as you mentioned which is totally irrelevant to missing one package!

  • if that does not work either, simply check if you are using the correct Python interpreter in the correct environment.

shahab4ai
  • 53
  • 1
  • 6
0

As for me, this happened because of the "Workspace Trust" thing, where normally you would open the file/files by right-clicking the folder from explorer and click "Open with VSCode". Instead, i opened the notebook's file directly with VSCode and the Workspace Trust tab shows up. The Workspace Trust makes almost all of your extension disabled, including the Jupyter's ones.

Normally, you can just trust your workspace/directory in the same session and your extensions will be reloaded without needing of restart, apparently this is not the case as the problem appeared and only disappeared after a VSCode restart.

So, TL;DR : Workspace Trust tab shows up > Trust the workspace > restart VSCode

Tommy Aria Pradana
  • 574
  • 1
  • 4
  • 18
0

I think you should try restarting VSCode.

0

Just uninstall Jupyter Notebook Extension in VScode Extension, Reload the VScode window then install back Jupyter Notebook extension and run the cells again. It sloved my problem

raviteja k
  • 94
  • 1
  • 1
  • 6