Getting Altair to work with Jupyter Notebook - jupyter-notebook

Trying to get Altair to work with Jupyter Notebook, I installed it using
conda install -c conda-forge altair vega_datasets notebook vega
But when I try to do an example plot
import altair as alt
from vega_datasets import data
# for the notebook only (not for JupyterLab) run this command once per session
alt.renderers.enable('notebook')
iris = data.iris()
alt.Chart(iris).mark_point().encode(
x='petalLength',
y='petalWidth',
color='species'
)
as seen in their quick start guide, I get
ValueError:
To use the 'notebook' renderer, you must install the vega package
and the associated Jupyter extension.
See https://altair-viz.github.io/getting_started/installation.html
for more information.
even though I have installed vega using Conda. I can make vega example plots though. I am unable to enable the Jupyter extension though, as Jupyter says it is incompatible.
Any help is appreciated.

For the current release of altair (Version 2.2), use
conda install -c conda-forge vega=1.3
or
pip install vega==1.3
and then restart the notebook.
The vega python extension was mistakenly updated this week to only support vega-lite 3.0, which is not yet released and thus not yet supported by Altair.
See https://github.com/altair-viz/altair/issues/1114 for the initial bug report.

Related

Azure Machine Learning notebooks: ModuleNotFound error

I'm working through a Python exercise using Azure Machine Learning notebooks. I'm unable to import torch even after !pip install torch.
Notebook says Requirement already satisfied, then errors out with:
!pip install torch
import torch
data = torch.tensor(encode(text), dtype=torch.long)
print(data.shape, data.dtype)
print(data[:100])
4 sec
ModuleNotFoundError: No module named 'torch'
Requirement already satisfied: torch in /anaconda/envs/azureml_py38/lib/python3.8/site-packages (1.12.0)
Requirement already satisfied: typing-extensions in /anaconda/envs/azureml_py38/lib/python3.8/site-packages (from torch) (4.4.0)
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Input In [22], in <cell line: 4>()
1 # Encode the entire dataset and store it into a torch.Tensor
3 get_ipython().system('pip install torch')
----> 4 import torch
5 data = torch.tensor(encode(text), dtype=torch.long)
6 print(data.shape, data.dtype)
ModuleNotFoundError: No module named 'torch'
I opened up a terminal in Azure ML Studio and tried pip install torch too, same Requirement already satisfied message showed.
How do I get torch (and any other Python modules where this occurs) working in AML notebooks?
I've found creating environments and installing packages through the terminal to be a much more reliable experience than doing it from an AML notebook.
I suggest using one of the provided terminals (either the one available in the compute instance's details, or the one available in JupyterLab) to create a new conda environment which you can customize to your liking.
Something like:
conda create -n my_tutorial python=3.10
conda activate my_tutorial
pip install --user ipykernel
python -m ipykernel install --user --name=my_tutorial
# Do a complete install of PyTorch, take a look at the available versions here https://pytorch.org/get-started/previous-versions/
conda install pytorch=1.13 torchvision=0.14 torchaudio=0.13 pytorch-cuda=11.7 -c pytorch -c nvidia -y
Afterwards, just make sure your notebooks use the my_tutorial kernel and you should be good to go. Whenever you want to pip install something new, just go back to the terminal, activate your kernel, and install the thing, then it should be available in your notebooks as well.
The issue was lined out in the docs here. Don't use !pip within the notebook. Instead use %pip.

Jupyter notebook view missing in Spyder ide even after install

Help, I am trying to use jupyter notebook in spyder , I've already installed the jupyter plugin via conda install spyder-notebook -c spyder-ide upon installation I restarted jupyter but the notebook tab is missing under the view tab in spyder.
Message of installation of notebook:
Screenshot of my views and panel tabs in spyder:
Unfortunately,
The Spyder notebook plugin is not yet compatible with Spyder 5 [...]. The latest version of spyder-notebook is compatible with Spyder 4.2[...]
See here. So either you can revert to Spyder 4.2 or wait for a solution. The issue is tracked here.

module 'torch.jit' has no attribute 'unused'

I am a student trying to get my hands into facial recognition using Ultra96 and I am having troubles running my program.
I have tried to install nightly version into my Ultra96 however, it does not solve my problem. The current OS is pynq 2.6 which is Linux and it is using jupyter notebook to run the codes.
Please offer me some guidance!
use torchvision 0.4.0:
pip uninstall torchvision
pip install torchvision==0.4.0 -f https://download.pytorch.org/whl/torch_stable.html
This will work for sure
EDIT : if above cmd wont work , use this pip install torchvision==0.4.0

can't import 'torchtext' module in jupyter notebook while using pytorch

I installed pytorch using anaconda3 and my created virtual conda environment named 'torchTest'.
I installed all the modules needed but, codes doesn't work in jupyter python.
I installed torchtext using
1.pip install https://github.com/pytorch/text/archive/master.zip
2.and also pip install torchtext too.
all I mentioned successfully downloaded in my MAC OS X, but can't get what's wrong with my Jupyter notebook..
After having the same issue with torchtext from within my jupyterlab, I opened an issue on Github at the jupyterlab project as well as at the torchtext repository.
My current solution is to add the PYTHONPATH from the Anaconda env.
The Anaconda path is usually like that $HOME/anaconda/bin
You can add it from within Jupyter Lab/Notebook like that:
import sys
sys.path.append("/some/path/to/add")
import torchtext

Using a Jupyter imported library?

Here is the big question:
Do i need to explicitly install a library, such as Plotly, in order for my locally hosted Notebook to import it?
Yes you need to have the library installed in your local environment to import it into your Jupyter Notebook.
However, you can check whether a package exists from within Jupyter Notebook and also automatically install it if it isn't already available.
you can run pip as well as shell commands from within a cell of the notebook
The syntax is as follows !pip install plotly Here the ! explicitly forces the kernel to execute the command.
If it's already installed you'll get this message Requirement already satisfied: plotly in /opt/conda/lib/python2.7/site-packages

Resources