Install Anaconda and jupyter notebook on Ubuntu 20

1. download and install latest Anaconda
curl -O https://repo.anaconda.com/archive/Anaconda3-2020.02-Linux-x86_64.sh
bash Anaconda3-2020.02-Linux-x86_64.sh
2. Activate and test Installation
~~source ~/.bashrc
conda list
3. install nodejs ~~
(base) ubuntu@ubunu2004:~$ conda install -c conda-forge nodejs
4. Set Up Anaconda Environments
conda create –name my_env python=3
conda activate my_env
5. install jupyter and matplotlib
pip install jupyter
pip install matplotlib
6. start jupyter notebook
(my_env) ubuntu@ubunu2004:~$ jupyter notebook
[I 15:45:31.229 NotebookApp] Writing notebook server cookie secret to /home/ubuntu/.local/share/jupyter/runtime/notebook_cookie_secret
[I 15:45:33.363 NotebookApp] Serving notebooks from local directory: /home/ubuntu
[I 15:45:33.365 NotebookApp] The Jupyter Notebook is running at:
[I 15:45:33.366 NotebookApp] http://localhost:8888/?token=d477ec6ca56d2382cc3f87392a06a8a6000a3aba2d367fc8
[I 15:45:33.372 NotebookApp] or http://127.0.0.1:8888/?token=d477ec6ca56d2382cc3f87392a06a8a6000a3aba2d367fc8
[I 15:45:33.373 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
7. create new sample.py code in jupyter notebook:
open http://localhost:8888/?token=d477ec6ca56d2382cc3f87392a06a8a6000a3aba2d367fc8 and create sample.py code:

import matplotlib.pyplot as plt; plt.rcdefaults()
import numpy as np
import matplotlib.pyplot as plt

objects = ('Python', 'C++', 'Java', 'Perl', 'Scala', 'Lisp')
y_pos = np.arange(len(objects))
performance = [10,8,6,4,2,1]

plt.bar(y_pos, performance, align='center', alpha=0.5)
plt.xticks(y_pos, objects)
plt.ylabel('Usage')
plt.title('Programming language usage')

plt.show()

Output:

  1. secure and bind jupyter on all IP
    (my_env) ubuntu@ubunu2004:~$ jupyter notebook –generate-config
    Writing default config to: /home/ubuntu/.jupyter/jupyter_notebook_config.py
    (my_env) ubuntu@ubunu2004:~$ jupyter notebook password
    Enter password:
    Verify password:
    [NotebookPasswordApp] Wrote hashed password to /home/ubuntu/.jupyter/jupyter_notebook_config.json
    {
    "NotebookApp": {
    "password": "sha1:de4ae15e9dcd:d32f371026e38a9241ec83a469de166b97ea60b7"
    }
    }

(my_env) ubuntu@ubunu2004:~$ openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout mykey.key -out mycert.pem
Generating a RSA private key ….

then you can vi /home/ubuntu/.jupyter/jupyter_notebook_config.py:

# Set options for certfile, ip, password, and toggle off
# browser auto-opening
c.NotebookApp.certfile = u'/home/ubuntu/mycert.pem'
c.NotebookApp.keyfile = u'/home/ubuntu/mykey.key'
# Set ip to '*' to bind on all interfaces (ips) for the public server
c.NotebookApp.ip = '*'
c.NotebookApp.password = u'sha1:de4ae15e9dcd:d32f371026e38a9241ec83a469de166b97ea60b7'
c.NotebookApp.open_browser = False

# It is a good idea to set a known, fixed port for server access
c.NotebookApp.port = 9999

start it with new port and binding:
(my_env) ubuntu@ubunu2004:~$ jupyter notebook
[I 16:48:20.227 NotebookApp] Serving notebooks from local directory: /home/ubuntu
[I 16:48:20.230 NotebookApp] The Jupyter Notebook is running at:
[I 16:48:20.230 NotebookApp] https://ubunu2004:9999/
Now you can open jupyter notebook from remote browser with your password!

Leave a Reply

Your email address will not be published. Required fields are marked *