ipympl: notebook backend not working in jupyterlab

I just installed this on top of my standard env, using conda-forge.

Using standard %matplotlib nbagg as activation command and using standard mpl plotting did not pop up any figure inside a jupyterlab notebook?

Using MPL 2.0 and jupyterlab v0.16 on a Python 3.5 env with conda on OSX 10.11.6 inside Safari 10.0.3

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 51 (22 by maintainers)

Most upvoted comments

In case others get here and are a little confused: At the beginning of your notebook, run %matplotlib ipympl, not %matplotlib notebook/nbagg.

For installation You need to install node.js. In the terminal, run

conda install notebook jupyterlab # for updating jupyter notebook and lab
pip install ipympl
jupyter labextension install @jupyter-widgets/jupyterlab-manager jupyter-matplotlib

This is now working (shown with pinned versions so this will always work):

pip install jupyterlab==0.28.11 ipympl==0.0.8
jupyter labextension install @jupyter-widgets/jupyterlab-manager@^0.28 jupyter-matplotlib@^0.1
jupyter lab
%matplotlib ipympl
import matplotlib.pyplot as plt
plt.plot([0,1,1,2])

Hi, any news about this issue?

ipympl is also available via conda, using the conda-forge channel.

You’ll need to use the current prerelease of jupyterlab pip install jupyterlab --pre, or you’ll need to install the previous release of the widget manager: jupyter labextension install @jupyter-widgets/jupyterlab-manager@0.31.

Ok, apparently npm must be installed too. I saw the statement that nodejs is required, but on Ubuntu installing nodejs does not automatically install npm.

Confirmed that it is still broken in the latest release, 0.21.0. Will try to look at this with @tacaswell next week.

Try -c conda-forgeinstead of -c conda forge

still not working (ipywidgets 6.0.0, matplotlib 2.0.2, jupyter lab: 0.25.2, Python 3.5.3). It would be appreciated to use nbagg in jupyter lab.

All you need to enable this is to import ipympl.

Oh, good catch!

Worked for me:

conda install jupyterlab jupyterlab_server tk nodejs
pip install ipympl
jupyter labextension install @jupyter-widgets/jupyterlab-manager jupyter-matplotlib

Then use %matplotlib widget in notebook.

PS : or maybe it was conda install -c defaults -c conda-forge ...

@johnmarktaylor91 You need to update ipykernel / ipython to a version that is aware of ipympl.

You can also monkey patch in the right information.

Use the current prerelease of jupyterlab worked for me! Thanks @jasongrout.

Looking again at the above - I realised I might not have the latest version of Jupyter Lab. So I ran conda install -c conda-forge jupyterlab

which upgraded Jupyter Lab to 0.31.0

Starting Jupyter Lab then asked for a rebuild - which I did. During the rebuild the following appeared in the bash script:

[3/4] 🔗  Linking dependencies...
warning "@jupyterlab/json-extension > react-highlighter@0.4.2" has unmet peer dependency "react@^0.14.0 || ^15.0.0 || ^16.0.0".
warning "@jupyterlab/json-extension > react-json-tree@0.10.9" has unmet peer dependency "react@^15.0.0".
warning "@jupyterlab/json-extension > react-json-tree@0.10.9" has unmet peer dependency "react-dom@^15.0.0".
warning "@jupyterlab/vdom-extension > @nteract/transform-vdom@1.1.1" has unmet peer dependency "react@^15.6.1".
[4/4] 📃  Building fresh packages...
[-/4] ⢀ waiting...
[2/4] ⢀ canvas: gyp
[3/4] ⢀ jupyter-matplotlib: > webpack
[-/4] ⢀ waiting...
warning Error running install script for optional dependency: "/Users/Chris/anaconda3/share/jupyter/lab/staging/node_modules/canvas: Command failed.\nExit code: 1\nCommand: node-gyp rebuild\nArguments: \nDirectory: /Users/Chris/anaconda3/share/jupyter/lab/staging/node_modules/canvas\nOutput:\ngyp info it worked if it ends with ok\ngyp info using node-gyp@3.6.2\ngyp info using node@8.9.3 | darwin | x64\ngyp info spawn /usr/local/bin/python2\ngyp info spawn args [ '/Users/Chris/anaconda3/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',\ngyp info spawn args   'binding.gyp',\ngyp info spawn args   '-f',\ngyp info spawn args   'make',\ngyp info spawn args   '-I',\ngyp info spawn args   '/Users/Chris/anaconda3/share/jupyter/lab/staging/node_modules/canvas/build/config.gypi',\ngyp info spawn args   '-I',\ngyp info spawn args   '/Users/Chris/anaconda3/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',\ngyp info spawn args   '-I',\ngyp info spawn args   '/Users/Chris/.node-gyp/8.9.3/include/node/common.gypi',\ngyp info spawn args   '-Dlibrary=shared_library',\ngyp info spawn args   '-Dvisibility=default',\ngyp info spawn args   '-Dnode_root_dir=/Users/Chris/.node-gyp/8.9.3',\ngyp info spawn args   '-Dnode_gyp_dir=/Users/Chris/anaconda3/lib/node_modules/npm/node_modules/node-gyp',\ngyp info spawn args   '-Dnode_lib_file=/Users/Chris/.node-gyp/8.9.3/<(target_arch)/node.lib',\ngyp info spawn args   '-Dmodule_root_dir=/Users/Chris/anaconda3/share/jupyter/lab/staging/node_modules/canvas',\ngyp info spawn args   '-Dnode_engine=v8',\ngyp info spawn args   '--depth=.',\ngyp info spawn args   '--no-parallel',\ngyp info spawn args   '--generator-output',\ngyp info spawn args   'build',\ngyp info spawn args   '-Goutput_dir=.' ]\nPackage cairo was not found in the pkg-config search path.\nPerhaps you should add the directory containing `cairo.pc'\nto the PKG_CONFIG_PATH environment variable\nNo package 'cairo' found\ngyp: Call to './util/has_lib.sh freetype' returned exit status 0 while in binding.gyp. while trying to load binding.gyp\ngyp ERR! configure error \ngyp ERR! stack Error: `gyp` failed with exit code: 1\ngyp ERR! stack     at ChildProcess.onCpExit (/Users/Chris/anaconda3/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:336:16)\ngyp ERR! stack     at emitTwo (events.js:126:13)\ngyp ERR! stack     at ChildProcess.emit (events.js:214:7)\ngyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)\ngyp ERR! System Darwin 16.7.0\ngyp ERR! command \"/Users/Chrisuccess Saved lockfile.
✨  Done in 30.58s.
[I 13:09:02.896 LabApp] > node /Users/Chris/anaconda3/lib/python3.6/site-packages/jupyterlab/staging/yarn.js run build:prod
yarn run v1.3.2

After reloading the Jupyter Lab page, the %matplotlib ipympl instruction triggered the same error traceback as in my original post above.

Great! Closing again, then.

@blink1073, thanks for the info! Knowing it works for you made me re-test with a clean, just-created conda env, and it’s now fine.

I was testing in an env I’d made exclusively to track jlab, but where I’ve upgraded jlab multiple times along the way. There must have been stale JS somewhere…

This points out the fact that right now, the upgrade process is still a bit rough: even though I’m isolating jlab into its own env with basically everything from conda and only lab and its dependencies being pulled in manually (plus plugins like this one), every now and then something will break in somewhat hard-to-diagnose ways.

Not complaining at all, just noting that fact so we’re aware of it (or at least I keep it more in mind 😃

We may want to remind that anyone having weird errors along the way, just nuke even their whole env and make it fresh. It’s a bit brutal as a solution, but honestly it’s a lot easier than tracking down where the problem may be coming from (and with good reproducibility habits, it’s actually pretty painless to nuke/recreate a known env).

Thanks again much!! When the install/upgrade path for this gets smoother, it’s going to be awesome for end users, in lab included.