Introduction to python: installation and use of Anaconda and Jupyter notebook
1. Install and use Anaconda
Anaconda means "python" in English, which is similar to python. It is python's package manager and environment manager.
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.
Select the version corresponding to your computer to download, and then install it according to the prompts of the installer.
The official download speed is relatively slow
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/
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
After the installation is complete, click the icon to start the program and enter the main interface
Select Environment——“root——“installed in turn
You can see a list of installed packages
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.
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.
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.
Cmd input python to check if the version is 3.85, input exit() to exit.
Enter conda --version to view the version:
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
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.
Click New on the right to open the new list and select to create a new "python3"
You can enter such a notebook interface.
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.
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.
"Services" - "Restart & Run All"
Press the capital letter M
Enter your own custom content
Run to see the effect, and enter the writing code mode
Of course, you can also do this by commenting with #:
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
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.
It is necessary to confirm whether the installed package is installed in the current environment.
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:
- #Add mirror source
- conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
- conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
- conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
- conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
- #Display search path
- conda config --set show_channel_urls yes
- # show mirror channel
- conda config --show channels
The demonstration is as follows:
The above is successful.
- 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
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.
pip install jupyter
Enter the following command in the terminal terminal and press Enter:
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! ! !
Related: Introduction to python: installation and use of Anaconda and Jupyter notebook
- 1. Install and use Anaconda
- 1. What is anaconda?
- 2. Why do I need to install anaconda?
- 3. How to install anaconda?
- 4, jupyter Chinese
- 5. How to manage packages?
- 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