Showing posts with label jupyter. Show all posts
Showing posts with label jupyter. Show all posts

Jupyter notebook download as pdf: nbconvert failed: Pandoc wasn't found. nbconvert failed: No suitable chromium executable found on the system. Please use '--allow-chromium-download' to allow downloading one.



Install Pandoc

After that you need to have XeTex installed on your machine:
  • Linux : TeX Live
  • Mac : MacTex
  • Windows : MikTex

Install nbconvert and pyppeteer

pip install nbconvert
pip install pyppeteer

Now we can convert an ipynb file to to PDF via HTML or via Tex.

jupyter nbconvert --to webpdf --allow-chromium-download filename.ipynb
or 


jupyter nbconvert --to pdf filename.ipynb

filename.ipynb is the filename of your file to be converted to a PDF file.

How to check docstring or method details of a method in Jupyter notebook?

When using a method in Jupyter notebook, it always comes convinient by checking docstring or method details of a method, e.g., what parameters the method have. Here we have two options to check those.

The first option is add "?" at the end of the method you would like to check and run the cell, which will give you the method details in a printed format.




The second option is using the combination of "shift+tab" keys with the mouse cursor inside the method bracket, which will show you method details in a format below.



Jupyter Notebooks not displaying progress bars

The progress bar does not show up, instead it is showing HBox(children=(FloatProgress(value=0.0, max=1.0), Label(value='In progress...')))


$ jupyter nbextension enable --py widgetsnbextension

# assuming you have already installed nodejs and jupyterlab

# otherwise you need to install nodejs and jupyterlab first (pip install jupyterlab)

$ jupyter labextension install @jupyter-widgets/jupyterlab-manager

How to Execute Python Script in Jupyter Notebook using a Specific Virtual Environment, How to list and remove kernels from Jupyter Notebook


# Suppose you are in an activate virtualenv named py2env

(py2env)$ 

# Then install jupyter within the active virtualenv
(py2env)$ pip install jupyter

# jupyter comes with ipykernel, but somehow you manage to get an error due to ipykernel, then for reference ipykernel package can be installed using:
(py2env)$ pip install ipykernel

# set up the kernel
(py2env)$ python -m ipykernel install --user --name py2env --display-name "Python2 (py2env)"

# Now we can start jupyter notebook
(py2env)$ jupyter notebook




How to list kernels of Jupyter Notebook

If we want to check the list of kernels in our Jupyter Notebook, and remove afterwards.

$ jupyter kernelspec list
This will give you a list of kernels as follows
Available kernels:
  hbnn            /home/parklize/.local/share/jupyter/kernels/hbnn
  iswctest        /home/parklize/.local/share/jupyter/kernels/iswctest
  milvus          /home/parklize/.local/share/jupyter/kernels/milvus
  py3.6           /home/parklize/.local/share/jupyter/kernels/py3.6
  py3.7tf2.3.0    /home/parklize/.local/share/jupyter/kernels/py3.7tf2.3.0
  py3.7tf2.4.1    /home/parklize/.local/share/jupyter/kernels/py3.7tf2.4.1
  pymc            /home/parklize/.local/share/jupyter/kernels/pymc
  xai             /home/parklize/.local/share/jupyter/kernels/xai
  python3         /home/parklize/anaconda3/envs/pymc_env/share/jupyter/kernels/python3

How to remove a kernel of Jupyter Notebook

If we want to remove one of them, for example, the following command removes the hbnn kernel.

$ jupyter kernelspec remove hbnn

How to use Jupyter notebook remotely

It is for the case when you want to use/access Jupyter notebook in the remote computer/server from your local/home computer.

Make sure you have installed Jupyter notebook in both remote and local computers.

1. In the remote computer, open your Jupyter notebook you want to open in the corresponding directory in the ternimal

jupyter notebook --no-browser --port=8888

2. In your local computer's terminal
ssh -N -f -L localhost:8888:localhost:8888 [username]@[your_remote_host_name]

3. You can now access the remote Jupyter notebook by typing
localhost:8888
in your browser!