Enable jupyter widgets - python

The jupyter widgets exension is not rendering the ui items. Have tried updating the client and enabling widgetsnbextension but code below :
!pip install --upgrade jupyter_core jupyter_client
!jupyter nbextension enable --py widgetsnbextension
from IPython.display import display
button = widgets.Button(description="Click Me!")
display(button)
def on_button_clicked(b):
print("Button clicked.")
button.on_click(on_button_clicked)
renders :
Requirement already up-to-date: jupyter_core in /usr/local/lib/python2.7/dist-packages
Requirement already up-to-date: jupyter_client in /usr/local/lib/python2.7/dist-packages
Requirement already up-to-date: traitlets in /usr/local/lib/python2.7/dist-packages (from jupyter_core)
Requirement already up-to-date: python-dateutil>=2.1 in /usr/local/lib/python2.7/dist-packages (from jupyter_client)
Requirement already up-to-date: pyzmq>=13 in /usr/local/lib/python2.7/dist-packages (from jupyter_client)
Requirement already up-to-date: tornado>=4.1 in /usr/local/lib/python2.7/dist-packages (from jupyter_client)
Requirement already up-to-date: enum34; python_version == "2.7" in /usr/local/lib/python2.7/dist-packages (from traitlets->jupyter_core)
Requirement already up-to-date: six in /usr/local/lib/python2.7/dist-packages (from traitlets->jupyter_core)
Requirement already up-to-date: decorator in /usr/local/lib/python2.7/dist-packages (from traitlets->jupyter_core)
Requirement already up-to-date: ipython-genutils in /usr/local/lib/python2.7/dist-packages (from traitlets->jupyter_core)
Requirement already up-to-date: singledispatch in /usr/local/lib/python2.7/dist-packages (from tornado>=4.1->jupyter_client)
Requirement already up-to-date: futures in /usr/local/lib/python2.7/dist-packages (from tornado>=4.1->jupyter_client)
Requirement already up-to-date: backports-abc>=0.4 in /usr/local/lib/python2.7/dist-packages (from tornado>=4.1->jupyter_client)
Enabling notebook extension jupyter-js-widgets/extension...
- Validating: OK
Button(description='Click Me!', style=ButtonStyle())
The text :
Button(description='Click Me!', style=ButtonStyle())
is rendered instead of a UI button
Is another library required ?

From http://ipywidgets.readthedocs.io/en/latest/user_install.html :
Question: When I display a widget or interact, I just see some text,
such as IntSlider(value=0) or interactive(children=(IntSlider(value=0,
description='x', max=1), Output()),
_dom_classes=('widget-interact',)). What is wrong?
Answer: A text representation of the widget is printed if the widget
control is not available. It may mean the widget JavaScript is still
loading. If the message persists in the Jupyter Notebook or
JupyterLab, it likely means that the widgets JavaScript library is
either not installed or not enabled. See the installation instructions
above for setup instructions.
Page refresh fixed issue for me. I think installs referred to in my question were still required.

In my case I had to run again the cells in the jupyter notebook. In the tab Widgets, selecting Save Notebook Widgets State should render the widgets everytime you open the notebook again, without having to re run it.

Related

ModuleNotFoundError: No module named 'flask_cors' on python anywhere

To state from the get go this is no criticism of pythonanywhere, but I want to run a script that used to work using the line:
from flask_cors import CORS
But I get the following error mesage:
ModuleNotFoundError: No module named 'flask_cors'
Then tried to install in my version of python:
pip3.9 install Flask-Cors
The result was:
Defaulting to user installation because normal site-packages is not
writeable Looking in links: /usr/share/pip-wheels Requirement already
satisfied: Flask-Cors in ./.local/lib/python3.9/site-packages (3.0.10)
Requirement already satisfied: Six in
/usr/local/lib/python3.9/site-packages (from Flask-Cors) (1.16.0)
Requirement already satisfied: Flask>=0.9 in
/usr/local/lib/python3.9/site-packages (from Flask-Cors) (2.0.0)
Requirement already satisfied: Werkzeug>=2.0 in
/usr/local/lib/python3.9/site-packages (from Flask>=0.9->Flask-Cors)
(2.0.1) Requirement already satisfied: itsdangerous>=2.0 in
/usr/local/lib/python3.9/site-packages (from Flask>=0.9->Flask-Cors)
(2.0.1 ) Requirement already satisfied: click>=7.1.2 in
/usr/local/lib/python3.9/site-packages (from Flask>=0.9->Flask-Cors)
(7.1.2) Requirement already satisfied: Jinja2>=3.0 in
/usr/local/lib/python3.9/site-packages (from Flask>=0.9->Flask-Cors)
(3.0.1) Requirement already satisfied: MarkupSafe>=2.0 in
/usr/local/lib/python3.9/site-packages (from
Jinja2>=3.0->Flask>=0.9->Flask-C ors) (2.0.1) 15:33 ~$ pip show
Flask-Cors
Name: Flask-Cors Version: 3.0.10 Summary: A Flask extension adding a decorator for CORS support Home-page:
https://github.com/corydolphin/flask-cors Author: Cory Dolphin
Author-email: corydolphin#gmail.com License: MIT Location:
/home/elksie5000/.local/lib/python3.9/site-packages Requires: Six,
Flask
What gives and how do I fix it?
I think you should try the following:
Go to your Bash Console in "Consoles" menu.
Open the bash control
Select your virtualenv:
For example my virtualenv name is flaskapp, I would wirte "workon
flaskapp" in the bash console.
Now type in your desired command
pip3.9 install flask-cors in your case (try in lower case)
Make sure you are working in the same virtualenv and the same python version
(I think you want to make an API using cors maybe)

Package is showing in conda list but can't find in anaconda channels

I was installing Natasha, and so I used pip with conda to install Natasha and it's dependencies. They all show in conda list. What it says if I use conda pip install Natasha (I'm using conda so I can make virtualenv with packages I got on conda-forge). Is long, I'll summarize.
Requirement already satisfied: Natasha in c:\getfunds\lib\site-packages (1.4.0)
Requirement already satisfied: razdel>=0.5.0 in c:\getfunds\lib\site-packages (from Natasha) (0.5.0)
Requirement already satisfied: ipymarkup>=0.8.0 in c:\getfunds\lib\site-packages (from Natasha) (0.9.0)
Requirement already satisfied: yargy>=0.14.0 in c:\getfunds\lib\site-packages (from Natasha) (0.15.0)
Requirement already satisfied: navec>=0.9.0 in c:\getfunds\lib\site-packages (from Natasha) (0.10.0)
Requirement already satisfied: pymorphy2 in c:\getfunds\lib\site-packages (from Natasha) (0.9.1)
Requirement already satisfied: slovnet>=0.3.0 in c:\getfunds\lib\site-packages (from Natasha) (0.5.0)
Requirement already satisfied: pymorphy2-dicts-ru<3.0,>=2.4 in c:\getfunds\lib\site-packages (from pymorphy2->Natasha) (2.4.417127.4579844)
When I try to make the virtualenv, I get a PackagesNotFound error even though all of the packages show up in conda list with pypi_0.
I think it's a channels problem, but I don't know what to add. My channel list :
https://conda.anaconda.org/pypi_0/win-64
https://conda.anaconda.org/pypi_0/noarch
https://repo.anaconda.com/pkgs/main/win-64
https://repo.anaconda.com/pkgs/main/noarch
https://repo.anaconda.com/pkgs/r/win-64
https://repo.anaconda.com/pkgs/r/noarch
https://repo.anaconda.com/pkgs/msys2/win-64
https://repo.anaconda.com/pkgs/msys2/noarch
I found out what it was! It wasn't a channel issue ( I mean maybe it could be solved by adding the right channel, but there is some kind of incompatible difference between pypi and conda-forge the pypi in my channel list are null links) I had tried setting:
conda config --set pip_interop_enabled True
And maybe that was a perquisite, I haven't tried disabling it and testing this following step.I had to use a pip install after I had activated the virtualenv because Natasha (as a pip install) couldn't be found by the default channels, I had to pip install directly into the virtual environment.

ModuleNotFoundError on virtual env Jupyter lab

I have created a virtual env and installed Jupyter notebood and jupyter lab
after import pandas I get ModuleNotFoundError: No module named 'pandas'
doing the same operation with jupyter notebook does not give me an error, which run in the same venv
I installed pandas into the venv, but got the same error
importing the native python modules works fine
inserting !pip install pandas in an empty cell above returns
Requirement already satisfied: pandas in /home/curwin/jupyterlab/venv/lib/python3.8/site-packages (1.1.3)
Requirement already satisfied: pytz>=2017.2 in /home/curwin/jupyterlab/venv/lib/python3.8/site-packages (from pandas) (2020.1)
Requirement already satisfied: python-dateutil>=2.7.3 in /home/curwin/jupyterlab/venv/lib/python3.8/site-packages (from pandas) (2.8.1)
Requirement already satisfied: numpy>=1.15.4 in /home/curwin/jupyterlab/venv/lib/python3.8/site-packages (from pandas) (1.19.2)
Requirement already satisfied: six>=1.5 in /home/curwin/jupyterlab/venv/lib/python3.8/site-packages (from python-dateutil>=2.7.3->pandas) (1.14.0)
I have install a kernel inside the venv with
ipython kernel install --user --name=.venv
and running notebooks from this kernel solved the problem

Importing matplotlib gives error even though installed

I was hoping someone could help me out.
System is MacOS Catalina.
Python 3.8
IDE: VS
I installed matplotlib using pip install matplotlib which I saw stuck in under python2.7. I uninstalled matplotlib and reinstalled it using pip3 install matplotlib and received the following message:
Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.7/site-packages (from matplotlib) (0.10.0)
Requirement already satisfied: numpy>=1.11 in /usr/local/lib/python3.7/site-packages (from matplotlib) (1.18.1)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.7/site-packages (from matplotlib) (2.4.6)
Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.7/site-packages (from matplotlib) (1.1.0)
Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.7/site-packages (from matplotlib) (2.8.1)
Requirement already satisfied: six in /Users/apple/Library/Python/3.7/lib/python/site-packages (from cycler>=0.10->matplotlib) (1.13.0)
Requirement already satisfied: setuptools in /usr/local/lib/python3.7/site-packages (from kiwisolver>=1.0.1->matplotlib) (46.0.0)
However, when I try to run my .py file with 'import matplotlib' it gives this error:
import matplotlib as mpl
ModuleNotFoundError: No module named 'matplotlib'
I've tried searching different sources for the solution but I am now stuck.
You are mostly running your python script with the command python your_file.py, try running as python3 your_file.py in your terminal. pip3 installs packages under python3, not the default python2.
This is because I believe your mac terminal uses python 2.x by default, therefore the command python uses python 2.x version and python3 uses 3.x version that is available to execute the files. So if you want to install any packages under python 2.x you use pip as the command and to install packages under python 3.x you use pip3 as the command

Unable to import Preprocesing python

I am using spyder Anaconda. I am unable to import
from preprocessing import parse_annotation,BatchGenerator
I tried to install preprocssing using,
pip install preprocessing
got following error,
Requirement already satisfied: preprocessing in
c:\users\shahik\anaconda3\lib\site-packages (0.1.13)
Requirement already satisfied: nltk==3.2.4 in c:\users\shahik\anaconda3\lib\site-
packages (from preprocessing) (3.2.4)
Requirement already satisfied: sphinx-rtd-theme==0.2.4 in
c:\users\shahik\anaconda3\lib\site-packages (from preprocessing) (0.2.4)
Requirement already satisfied: six in c:\users\shahik\anaconda3\lib\site-packages
(from nltk==3.2.4->preprocessing) (1.10.0)
notebook 5.3.1 requires terminado>=0.8.1, which is not installed.
notebook 5.3.1 has requirement jupyter_client>=5.2.0, but you'll have jupyter-
client 5.0.1 which is incompatible.
notebook 5.3.1 has requirement jupyter_core>=4.4.0, but you'll have jupyter-core
4.3.0 which is incompatible.
Also tried to install from conda commands but failed. How can I solve these compatibility or other issues?

Categories

Resources