Python Jupyter notebook Various methods of use recording __python

Source: Internet
Author: User
Tags jupyter jupyter notebook

I. Installation of Jupyter notebook 1.1 new version Anaconda Jupyter Currently, the latest version of the Anaconda is a jupyter notebook, no need to install separately
1.2 old version Anacodna need to install Jupyter

Jupyter Notebook installation of the official website

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

Specific installation methods: The official proposal to use Anaconda installation Jupyter installation completed Anaconda, if the Anaconda does not bring Jupyter Noterbook, then, open cmd, enter: Conda install Jupyter

This installed jupyter does not have the new a terminal function
After a variety of queries, it turns out that Windows does not have the terminal required TTY, so jupyter in Windows does not support terminal mode, and there is no plan to increase this support in the short term

Ii. Changing the working space of the Jupyter notebook 2.1 Mode One

"Not every time."

In its configuration file ipython_notebook_config.py, like the next sentence

# The directory to use for notebooks and kernels.
# c.notebookapp.notebook_dir = U '
1 2 3

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

# The directory to use for notebooks and kernels.
C.notebookapp.notebook_dir = U ' D:\Jupyter '
1 2 3

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

How to find the configuration file. Enter Jupyter notebook in cmd--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 and do not overwrite
If the profile does not exist, it will initialize the resulting configuration file

Enter in cmd: Ipython profile Create
Find out about the location of the Jupyter profile 2.2 way two trick (ACE) into the Working directory folder

Keyboard shift+ the right mouse button-> Open the command window here-> enter in the pop-up command window: Jupyter Notebook

Jupyter is opened to navigate to the current directory.
Three, Jupyter a variety of 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:ctrl-enter after execution

is the current cell into edit mode: Enter

Exit edit mode for the current cell: ESC

Delete the current cell: double D

Add line number to the current cell: single L

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

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

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

Add/Remove comments for one or more lines: CRTL/

Undo deletion of a cell: Z

Switch between the tabs of the browser: Crtl PgUp and Crtl PgDn

Quick jump to the first CELL:CRTL home

Quick jump to the last Cell:crtl end Four, Jupyter notebook how to import code

That is, the import code into the cell in Jupyter notebook 4.1 to load the Local. py file into a cell in Jupyter

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

Import Caffe
solvername = "/root/workspace"
Sovler = Caffe. Adamsolver (Solvername)
1 2 3

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

%load test.py #test. py is a python file under the current path
1

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

(3) You can see that after the run,%load test.py was automatically added to the annotation symbol #,test.py all the code in the current cell was load to 4.2 from the Network load code to Jupyter

Enter%load http://... in the cell, and then run the cell to load the corresponding address on the following load into the current cell;

Here is an example of importing a small example in Matplotlib color example code

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

%load test.py #test. py is a python file under the current path
1

Then, Shift+enter runs, you can see the following results:

As you can see, after the run,%load test.py is automatically added to the annotation symbol #,test.py all the code in the current cell is load to five, jupyter run the python file Using the Jupyter cell, you can run the Python file by running the following code in the cell:

%run file.py
1

file.py for the Python program you want to run, the results are displayed in the cell

Vi. Jupyter Some other trivial uses the 6.1 jupyter cell can be used as a UNIX command

To do this: add an exclamation point to the front of the UNITX command. ”

Example:
View Python version:!python--version
Run python file:!python myfile.py 6.2 Magic functions

Not too clear, specific details see the cell magics in IPython 6.3 get current working directory

The path where the currently running code is located
Concrete method: Current_path =%pwd
This gets the Current_path is the current working path of the word Fu Jing 6.4 using matplotlib drawing

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

%matplotlib Inline
1 Vii. markdown in the Jupyter

Reference 1
Markdown Grammar Manual (full version) Reference 7.1 set link in jupyter, you need to set two parts:

The location to jump to (the destination)
You need to add the following statement to the location you want to jump to:

<a id= ' the_destination ' ></
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.