0

I created a virtual environment called "fastai" by conda. I tried to install ipywidgets in it by

mamba install ipywidgets

Then I checked it and it did exist. But when I used

jupyter --version

I found the status of ipywidgets was "Not installed". I guessed it might be the problem of jupyter kernel, and I registered a kernel for my virtual environment fastai:

python -m ipykernel install --user --name fastai --display-name "Python (fastai)"

I checked the new kernel by

jupyter kernelspec list

and it did succeed. Then I opened a notebook by

jupyter notebook

and shifted the kernel to the one I created with my virtual env fastai. But I stilled failed to import ipywidgets in the notebook. What's more,

jupyter --version

also kept that ipywidgets could not be found. I checked my widgetsnbextension, but found both the base env and the virtual env had already had it. That's what I got in my Powershell. I wonder what's going on, and how I can use ipywidgets in my virtual env successfully.

7
  • 1
    You are probably making this hard for you and anyone else trying to help you because you are not being specific in your title with the terms relative some parts of you post. I suspect since you said mamba and conda you may be encountering something like this perhaps? The reference there is supposed to be here. Plus, maybe reading through this thread, not just the linked answer, may inspire some things to try? Commented Sep 2 at 14:46
  • If I ipywidgets is your only tripping point right now though, you may just be able to install it from within your running Jupyter .ipynb file. Especially since you say you successfully "shifted the kernel to the one I created with my virtual env fastai". So do that again and this time in the notebook try running %conda install conda-forge::ipywidgets, based on here. (Magic symbol is important.) That probably won't work though since conda is particular unless you are running this on a remote machine that may allow this process to work. ... Commented Sep 2 at 14:50
  • <continued> However, try it that way first as you should exclusively use conda/mamba when possible since you mentioning that means you choose it as primary package manager. I should have said this earlier, where you were successful at shifting the kernel, did you refresh the page you were trying to work on? ipywidgets does a lot of stuff in the page and so if you don't do a hard browser refresh first, you sometimes can fool yourself. So I suggest trying that first. Shift your kernel to the one you created and restart the kernel and then do a hard browser refresh. On a Mac in ... Commented Sep 2 at 14:54
  • <continued> Chrome it is Commad + SHIFT + r to do a hard refresh. Only after all that can you try ipywidgets. Now back to installing from within the running .ipynb file. If conda won't let you try the %conda install, and you really just want to get past this hurdle, you can try running in the active Jupyter cell after you shifted the kernel %pip install ipywidgets. Let that complete entirely and then restart the kernel and do a hard refresh on the browser page, and then even restart the browser and repeat that restart & refresh before trying ipywidgets. Commented Sep 2 at 14:57
  • Thank you for your reply. I tried all the methods you mentioned, but none of them worked. The result of trying to install ipywidgets inside the jupyter notebook is also that it showed all the package-requirements are already satisfied, but when I tried to import ipywidgets, it failed with the same ERROR. And it's also irrelative with kernels. That makes sense, as installing package in the notebook should have the same effect with installation in the Powershell. So this remains unclear for me. Commented Sep 4 at 14:25

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.