1

I have a problem that interactive objects from ipywidgets do not work in Jupyter Notebook on my computer. The widget itself is displayed but the function that it should control (e.g. drawing graph with changing parameter), seemingly, does not run. I took example from documentation and it does not work.

The picture of code and output

Code:

import ipywidgets
import widgetsnbextension

def greeting(text="World"):
    print("Hello {}".format(text))
ipywidgets.interact(greeting, text="IPython Widgets")

What have I already tried:

  1. There were similar questions, like this but the answer didn't work for me (the answer was to run this: jupyter nbextension enable --py widgetsnbextension).
  2. The code above works in GoogleColab so I tried to install their versions of packages ipython and ipykernel (packages ipywidgets and widgetsnbextensions were of the same version as mine). But it has led to errors so I have given up this idea. I have the latest versions of all packages now and I don't have Anaconda.

What should I try next? May be I am wrong and the problem has a different cause?

  • Did you try using another browser? – Nechoj Apr 22 '22 at 16:54
  • I've tried Google Chrome and Microsoft Edge. It didn't solve the problem. – appleivanko Apr 22 '22 at 20:04
  • It works in my Sage jupyter notebook as expected. It must be a problem in the environment, I guess. – Nechoj Apr 22 '22 at 20:05
  • Please also check whether your event loop is running: https://stackoverflow.com/questions/47518874/how-do-i-run-python-asyncio-code-in-a-jupyter-notebook – Nechoj Apr 22 '22 at 20:09
  • I've never used Sage. Do you mean SageMath? So, should I try to install it and run jupyter notebook with it? – appleivanko Apr 22 '22 at 20:14
  • Yes, SageMath. It is a very convenient environment to do Python developing with Jupyter notebooks. Many libs are included in the package. If you are using Jupyter 'naked' you are responsible for the Python environment. – Nechoj Apr 22 '22 at 20:18
  • Event loop is running. Checker gives the following: `<_UnixSelectorEventLoop running=True closed=False debug=False>` – appleivanko Apr 22 '22 at 20:50
  • The code works via SageMath, which is great! Thank you for this environment, I think, I will use it in the future, because it seemingly helps to keep all packages in right version. I think, my problem is solved now. – appleivanko Apr 22 '22 at 20:53
  • Sorry for the off-topic question but may be you can help me a little bit with SageMath. I need to install some packages (namely `pandas` and `scikit-learn`). I found on the Internet two ways to do it. 1) Use `sage -i packagename` in cmd, but it doesn't work, because cmd doesn't know this command (Windows 10). 2) Use `pip install packagename` in Sage Console/Shell. Using this I've managed to install `pandas` (it took about an hour though), but for `scikit-learn` it's broken with message `Failed building wheel for scipy`. – appleivanko Apr 23 '22 at 09:24
  • I'm little bit confused that installation of packages takes such time and doesn't work for `scikit-learn`. Do I do everything right? – appleivanko Apr 23 '22 at 09:26
  • Actually you do not need to install most packages as they are already included. Try running `sorted(pkgs.keys())` in SageMath shell to see the installed packages. https://doc.sagemath.org/html/en/reference/misc/sage/misc/package.html – Nechoj Apr 23 '22 at 09:33
  • See this tutorial to learn what is possible without installing packages https://doc.sagemath.org/html/en/thematic_tutorials/toctree.html – Nechoj Apr 23 '22 at 09:34
  • Another one: https://ask.sagemath.org/question/44977/is-it-possible-to-import-machine-learning-libraries-in-sage/ – Nechoj Apr 23 '22 at 09:36
  • I still don't understand how to use package on my computer. I wrote `list_packages(local=True).keys()`, which gave all possible packages in SageMath. It has `pandas` in it but does't have 'scikit-learn'. Then I wrote `installed_packages().keys()` and the output list does not contain both. So, the first question: how to move `pandas` to the second list? – appleivanko Apr 23 '22 at 10:11
  • Now, regarding the third-party packages like 'scikit-learn'. The reference you gave me above didn't help because `sage` command doesn't work in cmd. I tried to understand how to add Sage to PATH ([link](https://ask.sagemath.org/question/42035/how-to-put-sage-in-env-path-in-windows/)) but I didn't understand. – appleivanko Apr 23 '22 at 10:12
  • You do not need that. Open the Sagemath shell. There you can directly use `pip list` to see installed packages. – Nechoj Apr 23 '22 at 10:23
  • Yes, I know. There I have `pandas` (because I managed to install it - described above) and don't have `scikit-learn`. The question is how to install the second. And also I am confused that installation of `pandas` took an hour. – appleivanko Apr 23 '22 at 10:46
  • SageMath was developed for Linux. On Windows, it runs within a Linux emulation called cygwin. That's why building is slow. If you have a chance to run it natively under Linux that would be much better. E.g., inside a VirtualBox VM. – Nechoj Apr 23 '22 at 10:49
  • Thanks a lot! Finally, I found the solution of my problem and posted about it below. By the way, I managed to install `scikit-learn` in Sage Console using `pip` (it took three hours!!). After throwing a mistake it continued to install older version of the package and did it successfully. – appleivanko Apr 23 '22 at 15:57

1 Answers1

2

I found the answer!!!

I have had several nbextensions switched on (see screenshot). This was my mistake to include everything which seemed useful. When I turned off all nbextensions then all ipywidgets stuff started to work. Finally, I found that one particular extension called Limit Output is to be blamed for. Turn it off and all works fine.

The moral: don't use everything if you don't need it. Also, obviously, there is a bug in Limit Output extension because it is not supposed to affect widgets (it is supposed to limit output data when you accidentally write while(true) or something like that).

You can read some useful stuff about SageMath in the comments under the original question as well.