In Jupyter Notebook, ipywidgets work fine, however they seem to not work in Jupyter Lab (which is supposedly better than Notebook).
I followed these directions.
If you're on linux and you'd rather avoid conda entirely, and use virtual envs (venvs) to keep python happy, AND you happen to be using an 'older'/LTS Debian based OS, which may not have upto date nodejs: Ie, Ubuntu 16.04 LTS, which doesn't have a node
but rather nodejs
(node
belongs to another package, and the 'legacy nodejs' version is too old), then read on.
This is a little more complicated to setup, but much easier to maintain long-term than conda is. (you can always just mk a new venv
for a new project, without breaking your old projects).
Main points are:
So, all actual steps (these were tested to work on Linux Mint 18.3 Sylvia, which is basically compatible with ubuntu xenial aka Ubuntu 16.04 LTS. Differences will arise mostly in nodejs, read the readme in the github link above to solve for other OS):
Get an admin to do (or do yourself if you can sudo):
sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install -y python3.8 python3.8-dev python3.8-distutils python3-pip python3-venv
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -y nodejs
Then, as your own user, you can complete the rest of the steps:
pip3 install --user virtualenv virtualenvwrapper
mkdir ~/.envs
You'll then want to add the following to the end of your .bashrc
:
export PATH=~/.local/bin:$PATH
export WORKON_HOME=~/.envs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source ~/.local/bin/virtualenvwrapper.sh
At this point, make a new shell, and you will be able to run the rest of the setup, actually installing jupyterlab:
mkvirtualenv -p python3.8 jupenv
pip install jupyter matplotlib pandas ipympl tqdm
jupyter labextension install @jupyter-widgets/jupyterlab-manager
Now you're done.
To open/use jupyter, you want (because of the venv I've called jupenv
above, you can name it as you like in that mkvirtualenv
line):
workon jupenv
jupyter lab
Otherwise, I had no end of hell trying to get nodejs to work with outdated ubuntu packages. Sometimes it would work, for a few restarts, and then fail. Other times it would just keep giving me the same missing widgets, or sometimes little lines of junk js code.
Virtualenvs are well worth using, especially when you start using python seriously, and working with others who may use different versions / different sets of pip packages. VirtualEnvWrapper makes this pretty painless. The basic point is that everything you 'pip install', even jupyter, ends up being kept cleanly separate (and separate from the system packages), which keeps everything working very nicely.
There are some basic DO's and DON'T's:
pip install ...
lines without being in a venvpip3
in place of pip
within a venv.python
and not python3
to run within.conda...
!allvirtualenv pip install -U pip
As for the nodejs binary distribution packages: These are highly recommended where they support your particular OS. They'll be very up-to-date and should present the minimum of trouble.
JupyterLab now prefers a model where arbitrary javascript is no longer allowed to be embedded in a cell's output, which is how many interactive Jupyter Notebook modules used to work. They now ask that modules with interactivity create a JupyterLab extension. IPyWidgets has an extension that can be activated by running this on your command line (which assumes you already have NodeJS installed):
jupyter labextension install @jupyter-widgets/jupyterlab-manager