Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

notebook backend not working in jupyterlab #9

Closed
michaelaye opened this issue Feb 10, 2017 · 51 comments
Closed

notebook backend not working in jupyterlab #9

michaelaye opened this issue Feb 10, 2017 · 51 comments

Comments

@michaelaye
Copy link

michaelaye commented Feb 10, 2017

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

@SylvainCorlay
Copy link
Member

All you need to enable this is to import ipympl.

@michaelaye
Copy link
Author

Apparently, it must be done at the right time?

/Users/klay6683/miniconda3/envs/stable/lib/python3.5/site-packages/matplotlib/__init__.py:1401: UserWarning:  This call to matplotlib.use() has no effect
because the backend has already been chosen;
matplotlib.use() must be called *before* pylab, matplotlib.pyplot,
or matplotlib.backends is imported for the first time.

  warnings.warn(_use_error_msg)

@michaelaye
Copy link
Author

Still doesn't work. I put import ipympl now as the first line of import in my .ipython profile startup, but still no plot is popping up in jupyterlab v0.16.

@SylvainCorlay
Copy link
Member

@michaelaye I am sorry I replied from a mobile device earlier and missed that you were using jupyterlab.

We will add support for jupyterlab after we release ipywidgets 6.0.

@thomasaarholt
Copy link
Contributor

Could someone edit the title to "Notebook backend not working"?
It would be nice to get the notebook/nbagg backend working in jupyter lab. I know many users enjoy having an inline interactive backend.

@michaelaye michaelaye changed the title supposed to be working with jupyterlab v0.16? notebook backend not working in jupyterlab May 8, 2017
@danielballan
Copy link

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

@ElmWer
Copy link

ElmWer commented Jul 14, 2017

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.

@tacaswell
Copy link
Member

Hopefully this will get worked on at the jupytcon sprints next month.

@madx
Copy link

madx commented Aug 31, 2017

Hi, any news about this issue?

@blink1073
Copy link
Member

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])

@danielballan
Copy link

Thanks!

@thomasaarholt
Copy link
Contributor

thomasaarholt commented Nov 4, 2017

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

@michaelaye
Copy link
Author

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

@michaelaye
Copy link
Author

Are the interactivity features not yet ported? I don't see any zoom/pan etc icons?

@jasongrout
Copy link
Contributor

I tried this out the other day and was able to get mouse clicks to trigger python callbacks.

@fperez
Copy link
Member

fperez commented Dec 11, 2017

Should this be reopened for current versions of JLab? I followed @blink1073's instructions above to the letter, with jlab 0.28.11 and ipympl 0.0.8, and it works perfectly.

However, with the current version of JLab (0.30.5) and ipympl 0.1.0, I'm getting with either import ipympl or %matplotlib ipympl the same "Error displaying widget" message.

@blink1073 blink1073 reopened this Dec 11, 2017
@blink1073
Copy link
Member

blink1073 commented Dec 11, 2017

Hi @fperez! I just tried with Jlab (0.30.5) and ipympl 0.1.0 and it "Works on My Machine".

@blink1073
Copy link
Member

@jasongrout, any debug tips?

@fperez
Copy link
Member

fperez commented Dec 11, 2017

@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.

@jasongrout
Copy link
Contributor

Great! Closing again, then.

@pwuertz
Copy link

pwuertz commented Dec 14, 2017

On my machine the setup is failing at

$ jupyter labextension install @jupyter-widgets/jupyterlab-manager jupyter-matplotlib
> '' pack @jupyter-widgets/jupyterlab-manager
expected str, bytes or os.PathLike object, not NoneType

Already tried deleting and reinstalling the python user env, which worked for @fperez. The packages installed from pip are ipympl-0.1.0, jupyterlab-0.30.6. Any idea how to debug this?

@pwuertz
Copy link

pwuertz commented Dec 14, 2017

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.

@blink1073
Copy link
Member

Thanks @pwuertz, looks like we need a better check for whether npm is available.

@allefeld
Copy link

I'm getting the following error:

$ jupyter labextension install @jupyter-widgets/jupyterlab-manager jupyter-matplotlib
> /home/carstena/anaconda3/bin/npm pack @jupyter-widgets/jupyterlab-manager
jupyter-widgets-jupyterlab-manager-0.32.3.tgz

"@jupyter-widgets/jupyterlab-manager@0.32.3" is not compatible with the current JupyterLab
Conflicting Dependencies:
JupyterLab                        Extension            Package
>=0.13.1-0 <0.14.0-0              >=0.14.1-0 <0.15.0-0 @jupyterlab/application
>=0.13.0-0 <0.14.0-0              >=1.0.1-0 <2.0.0-0   @jupyterlab/coreutils
>=0.13.0-0 <0.14.0-0              >=0.14.1-0 <0.15.0-0 @jupyterlab/notebook
>=0.13.0-0 <0.14.0-0              >=0.14.1-0 <0.15.0-0 @jupyterlab/rendermime
>=0.4.3-0 <0.5.0-0                >=1.0.1-0 <2.0.0-0   @jupyterlab/rendermime-interfaces
>=0.52.0-0 <0.53.0-0              >=1.0.1-0 <2.0.0-0   @jupyterlab/services

Anaconda 3; jupyter lab & nodejs installed via conda; npm & ipympl via pip.

@jasongrout
Copy link
Contributor

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.

@chrisrb10
Copy link

chrisrb10 commented Jan 22, 2018

I'm also having this problem - and having followed advice above can't seem to resolve it.

I checked the following versions:
jupyterlab - 0.30.6 (conda installed) (NOTE - see update post below)
node.js - 6.11.2 (conda installed)
ipympl - 0.1.0 (conda installed)
npm - 5.5.1 (not installed directly - perhaps already present, perhaps installed when node.js installed)

MacOS 10.12.6

Trying to run jupyter lab triggered an instruction to rebuild jupyter lab - which I did.
Running the %matplotlib ipympl in a notebook triggered the error pasted below.
Any suggestions how to get the interactive charting in matplotlib working in JupyterLab?


%matplotlib ipympl error:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-1-e929c3fad522> in <module>()
      2 #%matplotlib notebook
      3 
----> 4 get_ipython().magic('matplotlib ipympl')
      5 
      6 # %matplotlib inline

/Users/Chris/anaconda3/lib/python3.6/site-packages/IPython/core/interactiveshell.py in magic(self, arg_s)
   2156         magic_name, _, magic_arg_s = arg_s.partition(' ')
   2157         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2158         return self.run_line_magic(magic_name, magic_arg_s)
   2159 
   2160     #-------------------------------------------------------------------------

/Users/Chris/anaconda3/lib/python3.6/site-packages/IPython/core/interactiveshell.py in run_line_magic(self, magic_name, line)
   2077                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2078             with self.builtin_trap:
-> 2079                 result = fn(*args,**kwargs)
   2080             return result
   2081 

<decorator-gen-104> in matplotlib(self, line)

/Users/Chris/anaconda3/lib/python3.6/site-packages/IPython/core/magic.py in <lambda>(f, *a, **k)
    186     # but it's overkill for just that one bit of state.
    187     def magic_deco(arg):
--> 188         call = lambda f, *a, **k: f(*a, **k)
    189 
    190         if callable(arg):

/Users/Chris/anaconda3/lib/python3.6/site-packages/IPython/core/magics/pylab.py in matplotlib(self, line)
     98             print("Available matplotlib backends: %s" % backends_list)
     99         else:
--> 100             gui, backend = self.shell.enable_matplotlib(args.gui)
    101             self._show_matplotlib_backend(args.gui, backend)
    102 

/Users/Chris/anaconda3/lib/python3.6/site-packages/IPython/core/interactiveshell.py in enable_matplotlib(self, gui)
   2933         """
   2934         from IPython.core import pylabtools as pt
-> 2935         gui, backend = pt.find_gui_and_backend(gui, self.pylab_gui_select)
   2936 
   2937         if gui != 'inline':

/Users/Chris/anaconda3/lib/python3.6/site-packages/IPython/core/pylabtools.py in find_gui_and_backend(gui, gui_select)
    261     if gui and gui != 'auto':
    262         # select backend based on requested gui
--> 263         backend = backends[gui]
    264     else:
    265         # We need to read the backend from the original data structure, *not*

KeyError: 'ipympl'

@chrisrb10
Copy link

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.

@thomasaarholt
Copy link
Contributor

@chrisrb10 I'd try uninstalling jupyterlab with conda and installing with pip install jupyterlab --pre per @jasongrout's instructions above.

@chrisrb10
Copy link

@thomasaarholt thanks - I tried that.
Got the same rebuild error code as above, and then the same error when I tried to run
%matplotlib ipympl in jupyter lab

If it is relevant - my Jupyter notebook is v.5.0.0. I have upgraded to more recent versions (5.2, 5.3) but each time I do I lose the ability to download as html (this issue) - so downgraded back to 5.0.0.

@astrojuanlu
Copy link

To all wanderers, make sure to conda install --channel conda-forge nodejs, not node.

@jarascript
Copy link

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

@johnmarktaylor91
Copy link

I have the same problem as chrisrb10 ("KeyError")... any luck on that front?

@SylvainCorlay
Copy link
Member

With the latest version of jupyter-matplotlib (0.2.1), the way to enable the interactive back-end is with

%matplotlib widget

@johnmarktaylor91
Copy link

This gives me the same problem with the KeyError.

@SylvainCorlay
Copy link
Member

Is ipympl installed?

@johnmarktaylor91
Copy link

Yup. "Import ipympl" works with no hitches.

@SylvainCorlay
Copy link
Member

What is the version of matplotlib?

@johnmarktaylor91
Copy link

2.0.0

@tacaswell
Copy link
Member

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

You can also monkey patch in the right information.

@johnmarktaylor91
Copy link

I updated ipykernel to the most recent version and still the same error.

@eiriklid
Copy link

I had to install yarn to be able to run jupyter labextension install @jupyter-widgets/jupyterlab-manager jupyter-matplotlib

before I got:

[1/4] Resolving packages...
error An unexpected error occurred: "https://registry.yarnpkg.com/@jupyterlab%2fapplication: self signed certificate in certificate chain".

After installing yarn I ran:
yarn config set "strict-ssl" false

When reopening the terminal it ran successfully!

@kiwi0fruit
Copy link

kiwi0fruit commented Nov 21, 2018

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 ...

@Chandrakantbhise
Copy link

Just go through this PATH definitely it will fix your problem
start -> anaconda or jupyter notebook prompt
step fist-> pip install nbconvert==5.4.1
step second -> python -m pip install --upgrade pip

please let me know once you fix it

@Bukharee
Copy link

when i try to install jupyter matplotlib using the command "conda install -c conda forge ipympl" on anaconda prompt here's the error that prompt
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.

PackagesNotFoundError: The following packages are not available from current channels:

  • forge

Current channels:

To search for alternate channels that may provide the conda package you're
looking for, navigate to

https://anaconda.org

and use the search bar at the top of the page.
solution please!!

@martinRenou
Copy link
Member

I fear you are mixing the conda-forge with other channels. I would suggest sticking with the conda-forge channel and not use other channels in the same environment, because that can bring issues. conda-forge should already contain everything you need.

@kiwi0fruit
Copy link

Try -c conda-forgeinstead of -c conda forge

@martinRenou
Copy link
Member

Oh, good catch!

@Bukharee
Copy link

Ok let me try

@Bukharee
Copy link

Thanks really helped

@baturevychvitalii
Copy link

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

thank you, for Arch it helped to install jupyterlab-widgets from the repository.

@martinRenou
Copy link
Member

Just a note that starting with jupyterlab v4, you should NEVER run jupyter labextension install @jupyter-widgets/jupyterlab-manager jupyter-matplotlib or any other jupyter labextension install commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests