introduce

Jupyter Notebook (previously known as IPython Notebook) is an interactive Notebook that currently runs in more than 40 programming languages.

The essence of Jupyter Notebook is a Web application that facilitates the creation and sharing of literary program documents, supporting real-time code, mathematical equations, visualization and Markdown. This is a great tool for visualization players, or for writing features that require step by step debugging.

The installation

throughAnacondaThe installation

Anaconda is an interesting piece of software, and an important part of Python, but there’s a lot of it on the web, and I can’t tell you much about it.

After downloading Jupyter, you will see the Jupyter icon in the startup panel.

Note: according to the personal installation of the package is not consistent, the display version and icon order will be different.

pipThe installation

  1. If you have only one version of Python installed, use the following command directly from the command line
python -m pip install --upgrade pip  # Install if PIP is not available, update if it is
pip install jupyter  # Install jupyter package
Copy the code
  1. If multiple Versions of Python are installed, the installation is based on the Python installation alias you setPython2Python3Under the premise of coexistence, setPython3An alias forpython3Use the following command, which is the same command for most Linux with Py2 and Py3 built in.
python3 -m pip install --upgrade pip
pip3 install jupyter
Copy the code

If Python2 and Python3 coexist, set the Python2 alias to Python2 using the following command if Python2 is already installed:

python2 -m pip install --upgrade pip
pip2 install jupyter
Copy the code

Well, in a non-Anaconda environment, multiple Python versioning is a pain in the neck.

First startup

  1. inAnacondaStartup in the environment

    Both of these ICONS appear in Windows+Anaconda environments, and if you haven’t changed any configuration, they should both start up in working directoriesThe documentDirectory, which is the document directory for the current user. Click both of these to launch, and the following popup window will appear after startup. Windows is almost the same as Linux, but some displays are different.

    I’m going to do this because of some SettingsThe current userThe root directory is set to the working directory. After successful startup, a page will be opened through the browser, and you can operate within the web page.

  2. Command line start Enter the command linejupyter notebook

    This uses the boot directory I set up earlier, so I usually use the command line to boot, better control the boot directory.

  3. Start and temporarily set up the working directory
jupyter notebook . # Set the current directory to a working directory and start the Jupyter notebook
jupyter notebook path # set path to working directory. Path can be any directory, but note the difference between Windows and Linux on directory separators
Copy the code

Jupyter set

Generating a Configuration File

Enter it on the command line

jupyter notebook --generate-config
Copy the code

If the command is executed successfully, a jupyter_notebook_config.py file is generated in % user directory %/.

Note Windows % user directory % is C:/Users/< login user name > Linux value Run CD ~ directory returned

If yes, the system prompts you whether it is overwritten. Enter y/N as required. The default value is not overwritten

Modify several common items

  1. c.NotebookApp.notebook_dirDefault working directory
  2. c.NotebookApp.passwordPassword, using SHA1 password string generated password string:
from notebook.auth import passwd
passwd()
Copy the code

Run the above command on the Python interactive command line and enter the password twice to get a password string of the form ‘sha1:< password >’. Assign the resulting password string (including the sha1 prefix) to c.notebookapp.password

These are some of the Settings I have encountered recently. For more, check out jupyter_notebook_config.py. It is important to note that all Settings in the configuration file are commented and you must uncomment them if you want to change them.

There may be a problem with starting Jupyter NoteBook from a shortcut in Windows

If you use the shortcut to start the system, the working directory does not work. Right-click the shortcut and click Properties

Use Visual Code to write the Jupyter NoteBook

Every time I started Jupyter NoteBook, a black box would pop up. It was hard to watch as an atypical OBSESSIVE, so I tried using Code. Ipynb file will render automatically after code installs the Python extension

Install other packages without restarting the service

When I am writing, I will encounter such a situation. When I am writing, I find that the package I want to use is not installed. I have to close it, install PIP, and start it again. So I checked to see if I could install a tripartite package without restarting the service. The existing scheme is as follows

Solution 1 Use commands

Enter the following command in the jupyter Notebook cell and execute:

! pip installCopy the code

Jupyter can access other commands in this way, for example! ls ! touch xxx.py

Plan 2 UsepythonThe script

import os
ok = False
while not ok:
    get_ipython().system('pip install numpy')OS. System (' PIP install numpy')
    try:
        import numpy
        ok = True;
    except:
        continue
Copy the code

This method is versatile and suitable for many Python environments, and can be used to install tripartite packages in scripts or other environments that cannot be rebooted, but it is also a stopgap.

conclusion

There are only so many preliminary uses of Jupyter Notebook, and more functions need to be excavated later.

Good not easy to come, to the public account a concern