Introduction to python: installation and use of Anaconda and Jupyter notebook

Article directory

1. Install and use Anaconda

1. What is anaconda?

2. Why do I need to install anaconda?

3. How to install anaconda?

Download page through the official website

Open source software download

installation steps:

 4, jupyter Chinese

5. How to manage packages?

1. List installed packages

2. Install or update the package

3. Open the conda command terminal

2. Using Jupyter Notebook

1. What is Jupyter Notebook?

2. Check if the installation is successful

3. How to start Jupyter Notebook?

4. How to use Notebook quickly?

1. 3 tabs at the top

2. How to create a new notebook?

3. The code runs:

4. Use skills:

1. Code auto-completion function

2. Rerun the code in all cells

3. Annotation editing

 4. Shortcuts

5. File - "Download as" can save the notebook in various formats

6. Shut down the notebook server

7. The installed package is not available in the notebook

3. Add mirror source

4. Module installation and uninstallation

pycharm install jupyter

1) Install

2) Run jupyter notebook


1. Install and use Anaconda

1. What is anaconda?

Anaconda means "python" in English, which is similar to python. It is python's package manager and environment manager.

2. Why do I need to install anaconda?

The reasons are as follows:

  • Comes with a large collection of popular data science packages so you can start working with data right away
  • management pack
  • Anaconda is developed on conda (a package manager and environment manager); and conda can easily install, uninstall and update third-party packages.
  • management environment
  • Conda can create different runtime environments for different projects, avoiding confusion and errors between different projects or package versions.

3. How to install anaconda?

Download page through the official website

Select the version corresponding to your computer to download, and then install it according to the prompts of the installer.

https://www.anaconda.com/distribution/

The official download speed is relatively slow

Open source software download

1. NetEase Open Source Mirror Site: Welcome to NetEase Open Source Mirror Site
2. Sohu Open Source Mirror Site: Index of /

3. Zhejiang University Open Source Software Mirror Site: http://mirrors.zju.edu.cn
4. Beijing Institute of Technology Open Source Software Mirror Site: http://mirror.bit.edu.cn

5. Huazhong University of Science and Technology Open Source Software Mirror Site: http://mirrors.hust.edu.cn/
6. Sun Yat-sen University Open Source Software Mirror Site: http://mirror.sysu.edu.cn/

7. Dalian University of Technology Open Source Software Mirror Site: Dalian University of Technology Open Source Software Mirror Site
8. Beijing Jiaotong University Open Source Mirror Site: http://mirror.bjtu.edu.cn

9. Lanzhou University Open Source Software Mirror Site: Lanzhou University Open Source Community Mirror Site
10. Shanghai Jiao Tong University Open Source Software Mirror Site: Index of /

11. Tsinghua University Open Source Software Mirror Site: Tsinghua University Open Source Software Mirror Site | Tsinghua Open Source Mirror
12. Tianjin University Open Source Software Mirror Site: http://mirror.tju.edu.cn/

13. University of Science and Technology of China Open Source Software Mirror: USTC Open Source Software Mirror
14. Northeastern University Open Source Software Mirror: http://mirror.neu.edu.cn/

installation steps:

Anaconda provides two versions of python2 and python3, select python3 to download and install. Since anaconda comes with python, there is no need to install another python program. Here because my computer is Windows 64-bit, so I downloaded the 64-bit Windows version, just click to download.

Wait after clicking. . .


Once the download is complete, find the file you downloaded:


Right click, run as administrator, click OK, then click Next, follow the steps to install:
 

 Select the location to install, it is recommended to install as recommended and click Next

 Check as appropriate, the first is to add environment variables, the second is to install python3.8, and then click Tnstall to install

Waiting for installation. . .

Installed, click Next 

 Click Finish to complete the installation

 4, jupyter Chinese

I will demonstrate the sinicization, but I do not recommend sinicization. If your English is really bad, you can sinicize it.

Computer - Right Click - Properties - Advanced System Settings - Environment Variables

 Note: The variable name is: LANG Variable value: zh_CN.UTF8
 After this is started, it is Chinese

5. How to manage packages?

After the installation is complete, click the icon to start the program and enter the main interface

1. List installed packages

Select Environment——“root——“installed in turn

You can see a list of installed packages

2. Install or update the package

In step 1, there is a "Search Packages" box in the upper right corner of the interface, you can search for packages. For example, search for "numpy"

You can see the corresponding package information, and click the tick in front of the package name to perform related operations on the package.

3. Open the conda command terminal

As shown in the figure, click the small triangle behind the root, you can see the open terminal option, click to open the conda command terminal, and manage the package through the command line.

2. Using Jupyter Notebook

1. What is Jupyter Notebook?

Jupyter notebook ( http://jupyter.org/ ) is a web application that allows users to combine explanatory text, mathematical equations, code, and visualizations all into one easily shareable document.

The advantage of Notebook is that narrative documentation can be written directly next to the code, instead of writing a separate document, allowing users to understand at a glance.

The name Jupyter is a combination of acronyms for three languages, Julia, Python, and R.

2. Check if the installation is successful

Cmd input python to check if the version is 3.85, input exit() to exit.

 Enter conda --version to view the version:

 

3. How to start Jupyter Notebook?

Anaconda already comes with Jupyter Notebook. In the main interface of the anaconda program, you can click "Launch" to open the notebook directly.

After clicking, the browser will automatically open the notebook page URL: localhost:8888; where localhost refers to your own computer, and 8888 is the default port of the server

4. How to use Notebook quickly?

1. 3 tabs at the top

The 3 tabs are: File, Run, Cluster

"Files" displays all files and folders in the current notebook working folder.

"Run" will list all running notebooks, which can be managed under this tab

"Clusters" are used to create multiple cores for parallel computing and are generally not used.

2. How to create a new notebook?

Click New on the right to open the new list and select to create a new "python3"

You can enter such a notebook interface.

3. The code runs:

You can type code directly in it, and press ctrl+enter to run it directly.

Such a small box is called a "cell". As the code runs, the cells are numbered (In[ ] on the left). When running multiple cells at the same time, you can clearly see what code is running and in what order.

Press shift+enter to add a cell.

Most of the work in a notebook is done in cells, where code is written and executed. Various operations can be performed in code cells, such as writing code, assigning values ​​to variables, importing packages, displaying data analysis results, etc. Any code executed in one cell is available in all other cells.

4. Use skills:

1. Code auto-completion function

Example: First define a variable name, when you need to use the variable in the following code, you only need to enter the first letter n of the variable, and then press the tab key, the variable starting with the letter n will automatically pop up in the code. Name, press the enter key to select, which can greatly improve the efficiency of code input.

It should be noted that if you want the defined variable to appear in the code completion, you need to run the cell (cell) that defines the variable before the notebook can be recognized normally.

When * appears before Cell , it means that the current cell program is running or waiting to run; if the previous cell enters an infinite loop or has not finished running, the latter cell will not run.

2. Rerun the code in all cells

"Services" - "Restart & Run All"

3. Annotation editing

  1. Press ESC

  2. Press the capital letter M

  3. Enter your own custom content
    insert image description here

  4. Run to see the effect, and enter the writing code mode
    insert image description here

Of course, you can also do this by commenting with #:
insert image description here

 4. Shortcuts


Enter : Enter the editing mode
Shift-Enter : Run this unit, select the next unit
Ctrl-Enter : Run this unit
Alt-Enter : Run this unit, insert a new unit under it
Y : The unit is transferred to the code state
M : The unit is transferred Enter markdown state
R : Unit goes to raw state
Tab : Code completion or indent
Shift-Tab : Prompt
Ctrl-] : Indent
Ctrl-[ : Unindent
Ctrl-A : Select all
Ctrl-Z : Restore
Esc : Enter Command mode
Ctrl-M : enter command mode

5. File - "Download as" can save the notebook in various formats

  • 6. Shut down the notebook server

Just close the notebook page. Make sure all files are saved before closing.

After closing the notebook, the next time you open it, you need to select "Restart&Run all" in the "Services" tab of the notebook to recompile the previous code, otherwise you may encounter the problem that the variables cannot be accessed.

7. The installed package is not available in the notebook

It is necessary to confirm whether the installed package is installed in the current environment.

3. Add mirror source

Check it out before configuring:

conda config --get channels


2. Delete the previous mirror source and restore the default 

conda config --remove-key channels

3. Add the Tsinghua mirror source and execute the commands in sequence:

  1. #Add mirror source
  2. conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  3. conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
  4. conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  5. conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
  6. conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
  7. #Display search path
  8. conda config --set show_channel_urls yes
  9. # show mirror channel
  10. conda config --show channels

The demonstration is as follows:

The above is successful.



4. Module installation and uninstallation

Precautions:

  • put an exclamation mark in front of pip
  • Both installation and uninstallation can be done with an exclamation mark
    . For example, I install the numpy module:
!pip install numpy


To uninstall it is: 

!pip uninstall numpy



pycharm install jupyter

As a loyal fan of pycharm, I have to think of pycharm. On this, we can also install jupyter. After installation, its usage is the same as described above.



1) Install

terminal execution:

pip install jupyter

Demo:



2) Run jupyter notebook

Enter the following command in the terminal terminal and press Enter:

jupyter notebook

The terminal interface is like this:


At the same time, it will also jump out of the jupyter page:


Other operations are the same as the above demonstrations, so I will not demonstrate them one by one here!! If there are any mistakes in this article, please correct me, thank you! ! !

Tags: Introduction to python: installation and use of Anaconda and Jupyter notebook

python crawler machine learning python basics python jupyter Development language

Related: Introduction to python: installation and use of Anaconda and Jupyter notebook