The Jupyter Notebook is an open-source interactive web application developed by Python language. The official recommends installing Python and Jupyter Notebook using the Anaconda Distribution. This article documents how to set up Anaconda and Jupyter Notebook, and implement the entire process through a shell script.
We are changing versioning in Anaconda Distribution from a
major/minor
version scheme to ayear.month
scheme. We made this change to differentiate between the open source Anaconda Distribution and Anaconda Enterprise, our managed data science platform. Conda, will continue to use amajor/minor
versioning scheme. – Anaconda Distribution 2018.12 Released
Introduction
We strongly recommend installing Python and Jupyter using the Anaconda Distribution, which includes Python, the Jupyter Notebook, and other commonly used packages for scientific computing and data science. – Installing Jupyter
Anaconda
Anaconda Distribution is the easiest way to do Python data science and machine learning. It includes 250+ popular data science packages and the conda package and virtual environment manager for Windows, Linux, and MacOS. Conda makes it quick and easy to install, run, and upgrade complex data science and machine learning environments like Scikit-learn, TensorFlow, and SciPy. Anaconda Distribution is the foundation of millions of data science projects as well as Amazon Web Services' Machine Learning AMIs and Anaconda for Microsoft on Azure and Windows. – https://www.anaconda.com/what-is-anaconda/
Jupyter
The Jupyter Notebook is an open-source web application that allows you to create and share documents that contain live code, equations, visualizations and narrative text. Uses include: data cleaning and transformation, numerical simulation, statistical modeling, data visualization, machine learning, and much more. – https://jupyter.org/
Official Document
- Conda
- Anaconda https://docs.anaconda.com/anaconda/
- Jupyter
Conda provides cheat sheet for a single-page summary of the most important information about using conda.
Shell Script
The entire installation and configuration process has been implemented through a shell script, the code is hosted on GitLab, usage info
|
|
To facilitate managing Jupyter Notebook, I set up some command aliases in ~/.bashrc
, as follows
|
|
jnl
:list running server;jnb
:start new server;jne
:stop all started server;jni
:search, install, update package viaconda
, use commandjni a
to update entire conda environment;jnr
: remove package viaconda
Anaconda
Official download page is https://www.anaconda.com/download, it supports both Python 3.7 and 2.7. Choosing the corresponding version according to your needs.
Release Version
The latest release version of Anaconda is 2019.03
.
You can use the following command to extract the latest version information
|
|
Output results
|
|
Release Date | Version |
---|---|
April 04, 2019 | 2019.03 |
December 21, 2018 | 2018.12 |
November 19, 2018 | 5.3.1 |
May 30, 2018 | 5.2.0 |
February 15, 2018 | 5.1.0 |
Verification
Anaconda doesn’t provide hash verification info for the package directly on its download page. The relevant information is stored on the documentation page Anaconda installer file hashes. The page Hashes for all files lists the sha256 hash values of the historical versions of Anaconda.
Here take Anaconda3-2019.03-Linux-x86_64.sh
as an example, the page Hashes for Anaconda3-2019.03-Linux-x86_64.sh lists the installation package information.
item | details |
---|---|
Last Modified | 2019-04-04 16:00:31 |
size(byte) | 685906562 |
md5 | 43caea3d726779843f130a7fb2d380a2 |
sha256 | 45c851b7497cc14d5ca060064394569f724b67d9b5f98a926ed49b834a6bb73a |
Hash check can be performed by the following command
|
|
Demonstration example
|
|
Installation
After the sha256 check is passed, refer to the official document https://docs.anaconda.com/anaconda/install/ for installation.
Run the following command to install
|
|
By default, the installing process of Anaconda is interactive which requires user interaction , details in Installing on Linux.
It also supports silent mode installation, according to official documents
- https://conda.io/docs/user-guide/install/index.html#installing-in-silent-mode
- https://conda.io/docs/user-guide/install/linux.html#install-linux-silent
- https://conda.io/docs/user-guide/install/macos.html#install-macos-silent
Specifing flag -b
to make it into silent mode, you can also specify flag -p
to custom installation path, as explained below:
- -b: Batch mode with no PATH modifications to
~/.bashrc
. Assumes that you agree to the license agreement. Does not edit the.bashrc
or.bash_profile
files. - -p: Installation prefix/path.
- -f: Force installation even if prefix -p already exists.
Here use installation path /opt/Anaconda
as an example, the installation command is
|
|
$PATH
After Anaconda is installed, it still can’t directly execute the command conda
. The reason is that the executable path ${installation_dir}/bin/
is not in the environment variable $PATH.
You need to use ${installation_dir}/bin/activateadd
to add into $PATH
.
Anaconda just adds the following directive into file ~/.bashrc
.
|
|
But personal advice is place it under directory /etc/profile.d/
, so that other users can also use conda
.
Run the following command to update
|
|
Jupyter
As Anaconda includes Jupyter Notebook, what you need to do is change its default configuration.
Jupyter Notebook listens on the default port 8888
, logging in via a password or token.
Generate the configuration file through the following command
|
|
The generated configuration file path
|
|
Details in Configuration Overview
The important directive
NotebookApp.allow_root
NotebookApp.base_url
NotebookApp.ip
NotebookApp.port
c.NotebookApp.password
NotebookApp.allow_password_change
NotebookApp.notebook_dir
NotebookApp.certfile
NotebookApp.disable_check_xsrf
For remote access, you need to open the Jupyter port (default is 8888
) in firewall rule.
Password Generation
Jupyter Notebook uses an interactive way to generate hashed password.
Interactive mode
Official document Alternatives to token authentication mentioned
New in version 5.0: jupyter notebook password command is added.
The generated hashed password stores in file
|
|
The demo process is as follows (raw password [email protected]$(date +'%Y')_Python
)
|
|
Silent Mode
But the interactive mode is not conducive to the automatic operation of the shell script. If there is a possibility to generate hashed password in silent mode?
Here use Python 3 as an example, the functions used by Jupyter Notebook to generated hashed password are passwd
、passwd_check
、set_password
、persist_config
, they lists in file
|
|
Extracting the core codes into file /tmp/passwd.py
, here still use the raw password [email protected]$(date +'%Y')_Python
as an example.
|
|
executing the following command to generated hashed password
|
|
operating process
|
|
The verification result is True
.
However, there is a problem with this: Anaconda supports both Python 3 and 2, there are 2 security.py
copies need to be processed separately. If Jupyter Notebook changes the code, the shell script must also be changed accordingly. I’m not ensure that the script can be updated in time. Based on this consideration, this function (custom password setting) was not added to the shell script.
SSL
To improve the security of data transmission, SSL certificates can be configured. More details in Using SSL for encrypted communication.
Here I use command openssl
to create a self-signed SSL certificate. This process is also in interactive mode. However, you can disable it by flag -subj
.
Shell code sample
|
|
The testing process is as follows
|
|
Jupyter Extension
In order to enhance the function of Jupyter Notebook, you could consider installing extension jupyter_contrib_nbextensions. More details in Unofficial Jupyter Notebook Extensions.
|
|
Testing
Command Line
|
|
Web Browser
Private SSL
Reference
Change Logs
- 2018.04.19 10:42 Wed America/Boston
- first draft
- 2018.07.11 11:38 Wed America/Boston
- update version to
5.2
- update version to
- 2018.11.29 10:45 Thu America/Boston
- update version to
5.3.1
- update version to
- 2018.12.22 19:27 Sat America/Boston
- Anaconda change verson schema from
major/minor
toyear.month
,update version to2018.12
, details in Anaconda Distribution 2018.12 Released.
- Anaconda change verson schema from
- 2019.04.09 13:32 Tue America/Boston
- update version to
2019.03
- update version to