Python Jupyter notebook Various use methods

Source: Internet
Author: User
Tags jupyter jupyter notebook

    • Pythonjupyter notebook Various Use methods record continuous update
    • Installation of a Jupyter notebook
      • 1 new version Anaconda comes with Jupyter
      • 2 old version Anacodna need to install Jupyter
    • Two changes to Jupyter notebook workspace
      • 1 Way One
      • 2 Way two trick trick
    • Various shortcut keys for three jupyter
    • Four Jupyter notebook how to import code
      • 1 Load the local py file into a cell in Jupyter
      • 2 from the Network load code to Jupyter
    • Five Jupyter running Python files
    • Six Jupyter some other trivial usage
      • The 1 Jupyter cell can be used as a UNIX command
      • 2 Magic functions
      • 3 Getting current working directory
      • 4 Drawing with Matplotlib
    • The markdown in the seven Jupyter
      • 1 Setting up link in jupyter requires two parts
      • 2 adding directory features to Jupyter notebook

Jupyter notebook) Formerly known as Ipython Notebook, when learning, you can find the two tutorials

  • Jupyter Project Documentation
  • Jupyter Notebook Documentation
  • Jupyter/ipython Notebook Quick Start Guide
  • Old IPython Notebook homepage
I. Installation of Jupyter notebook 1.1 new version Anaconda comes with Jupyter
    • Currently, the latest version of the Anaconda is self-jupyter notebook and does not need to be installed separately
1.2 old version Anacodna need to install Jupyter

Jupyter Notebook installation of the official website

    • Prerequisites for installing Jupyter notebook: Python is already installed (Python 2.7 or python3.3)

    • Specific installation methods:

      • Official recommendation to install Jupyter using anaconda
      • After the installation completes Anaconda, if the Anaconda does not bring Jupyter Noterbook, then open cmd and enter:conda install jupyter
    • This installs the Jupyter does not have the function of new a terminal
      After a variety of queries to know that the original is because Windows does not have terminal required TTY, so, Windows Jupyter is not supported terminal mode, and in the short term there is no plan to increase this support

Second, change the working space of Jupyter Notebook 2.1 way One

"Not every time."

In its configuration file ipython_notebook_config.py, as in the next sentence

to use for notebooks and kernels.# c.NotebookApp.notebook_dir = u‘‘
    • 1
    • 2
    • 3

The sentence is used to specify the workspace, for example, the default workspace is: User name folder, for example, now you want to change the workspace to D:\Jupyter, then you need to make the following changes (remember to delete the comment #)

# The directory to use for notebooks and kernels.c.NotebookApp.notebook_dir = u‘D:\Jupyter‘
    • 1
    • 2
    • 3

Note: Do not add a symbol "\" After the last level of the path

How do I find the profile?

    • Enter in cmdjupyter notebook --generate-config
    • If the configuration file already exists, the following information appears, where you can see where the configuration file exists, note that at this point, enter N, do not overwrite
    • If the profile does not exist, a configuration file will be initialized to produce a

In cmd, enter: ipython profile create
You can find the location of the configuration file about Jupyter

2.2 Way two trick (trick)
    • Go to Working Directory folder
    • Keyboard shift+ Right-click here to open a command window, enter in the command window that pops up: Jupyter Notebook

    • Jupyter is opened, navigate to the current directory!

Three, Jupyter of various shortcut keys
    • Executes the current cell and automatically jumps to the next cell:Shift Enter

    • Executes the current cell and does not automatically switch to the next cell after execution:Ctrl-Enter

    • is the current cell into edit mode:Enter

    • Exit the current cell's edit mode:Esc

    • Delete the current cell: double D

    • Add line number to the current cell: single L

    • Converts the current cell to a maskdown with a first-level title: Single 1

    • Converts the current cell to a maskdown with a level two title: Single 2

    • Converts the current cell to a maskdown with a level three title: Single 3

    • Add/Uncomment a line or multiple lines:Crtl /

    • To undo the deletion of a cell:z

    • Switch between tabs of the browser: Crtl PgUp andCrtl PgDn

    • Quick jump to first cell:Crtl Home

    • Quickly jump to the last cell:Crtl End

Iv. Jupyter Notebook How to import code

That is, import the code into the cell Jupyter notebook.

4.1 Load the Local. py file into a cell in Jupyter

Issue background: There is a test.py file that needs to be loaded into a cell in Jupyter
test.py content is as follows:

import caffeSolverName = "/root/workspace"sovler = caffe.AdamSolver(SolverName)
    • 1
    • 2
    • 3

Method steps:
(1) Enter in the cell where you want to import the segment code

%load test.py #test.py是当前路径下的一个python文件
    • 1

(2) Run the cell
Using the shortcut key "Shift+enter", you can see the following results:

(3) can be seen, after running, %load test.py is automatically added to the comment symbol #,test.py all the code in the current cell is load

4.2 From the Network load code to Jupyter
    • Entering in the cell %load http://..... , and then running the cell, will load the code corresponding to the address behind the load into the current cell;

    • Here is an example of importing matplotlib in a small example of color example code

      • First, enter in the cell where you want to import the segment code

        %load test.py #test.py是当前路径下的一个python文件
        • 1
      • Then, Shift+enter runs, you can see the following results:

        As you can see, after running, it %load test.py is automatically added to the comment symbol #,test.py all the code in the current cell is load

V. Jupyter running Python files
    • Using the Jupyter cell is a Python file that runs the following code in the cell:
%run file.py
    • 1

file.py is the Python program to run, the results are displayed in the cell

Vi. Jupyter Some other trivial usage 6.1 Jupyter's cell can be used as a UNIX command

To do this, add an exclamation mark in front of the UNITX command "! ”

Example:
To view the Python version: !python --version
To run a python file:!python myfile.py

6.2 Magic Functions

Not quite clear, see the cell magics in IPython for specifics.

6.3 Getting Current working directory

The path where the code that is currently running is located
Specific methods: current_path = %pwd
This current_path is the character of the current working path.

6.4 Drawing with Matplotlib

In Jupyter notebook, if you use a matplotlib drawing and sometimes you can't bounce an image frame, you can add it at the beginning

%matplotlib inline
    • 1
Vii. the markdown in Jupyter

Reference 1
Markdown Grammar Handbook (full finishing edition) reference

7.1 To set up link in jupyter, you need to set up two parts:
    • The location to jump to (the destination)  

      < A id= ' the_destination ' ></< Span class= "Hljs-title" >A>        
      • 1

      Here the ID value is arbitrarily assigned, the following when adding a link with

    • Need to add a link to the text (an internal hyperlink to the destination), Click here to jump to the destination and add it after the text that needs to be added:

       [ need to add connected text (   
      • 1
    • The following is an example:   ;
      Source:  


7.2 Adding directory features to Jupyter notebook
    • The original jupyter is not supported by the Markdown Add directory feature
    • In fact, it is possible to use Jupyter notebook extensions to make this function
    • Specific methods:
      • Install Jupyter Notebook extensions with Anaconda
        conda install -c conda-forge jupyter_contrib_nbextensions
      • Open Jupyter Notebook, under its (new) Nbextensions tab, tick "Table of Contents (2)"
      • Opens a. jpynb file and discovers that the directory feature is available!

Reference documents
[1] Adding a directory for Jupyter notebook

Copyright NOTICE: This article for Bo Master original article, if need to reprint, please specify Source: Http://blog.csdn.net/tina_ttl

Python Jupyter notebook Various use methods

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.