The foreword 0.

Reading this note requires a good understanding of Python and an interest in statistical analysis or machine learning

1. About Anaconda and Jupyter Notebook

If you want to know more about Jupyter Notebook and are fluent in English, please go to the Jupyter Notebook website

Cris recommends Anaconda as The Most Popular Python Data Science Platform for Data analysis and package management

For details on how to install and use Anaconda, please refer to this article, which covers Windows, Mac, and Linux

Because Anaconda is quite large, if you want a simplified version, you can install Miniconda. How to install it, please search baidu by yourself

How to use Jupyter Notebook, this article has given a very detailed solution, but Cris still hope to share some of their own use skills, summed up experience, learn from each other, upupup!

Jupyter Notebook is a lightweight, WYSIWYG (what YOU see is what you get) Web editor for Python. It’s a must-have tool for data analysis and machine learning.

Miniconda is partially Windows based and Anaconda is partially Linux based

Of course, both Anaconda and Miniconda are available on all three platforms, so if it’s too much hassle, install Anaconda, and if you want to simplify, install Miniconda

2. Use Anaconda(Miniconda) and Jupyter Notebook

2.1 Installation of Miniconda and Jupyter Notebook

Miniconda is a subset of Anaconda. It is much smaller than Anaconda and therefore smaller. However, third-party packages and tools need to be installed by themselves

In fact, the use of Miniconda is almost the same as that of Anaconda. First, let’s briefly talk about how Miniconda installs and uses Jupyter Notebook

The Jupyter Notebook needs to be installed first

After the installation is complete, you can start the jupyter notebook command

However, Anaconda(Miniconda) often builds different virtual environments according to different projects. Here, Miniconda of Cris is used as an example

Jupyter Notebook is currently installed in the default Base environment. If we want Jupyter Notebook to recognize the Test virtual environment, we also need to install the Kernel package of The Test virtual environment

(base) C:\Users\cris>conda activate test
Copy the code

First switch to the Test virtual environment, and then run the following command

conda install -n python_env ipykernel
Copy the code

Python_env is the name of your virtual environment,Cris, test. After the command is executed, return to the Base environment and restart the Jupyter Notebook

Jupyter Notebook can then recognize different virtual environments

Note: If Jupyter Notebook still doesn’t recognize virtual environments (mostly Miniconda users), you’ll also need to install the NB_conda package in the Base environment

(base) C:\Users\cris>conda install nb_conda
Copy the code

Then restart the Jupyter Notebook to see the virtual environment

2.2 Installing and Using Anaconda(Miniconda

About Anaconda, website

Wikipedia

Anaconda is a freemium, open source distribution of the Python language for large-scale data processing, predictive analytics, and scientific computing that aims to simplify package management and deployment. Anaconda uses the software package management system Conda for package management.

Anaconda is a tool for managing the Python package environment and deployment. It also comes with a number of toolkits for handling data, such as: Pandas, NumPy, etc., anda web version of the Jupiter Notebook editor for writing Python data handling code. Similar to pip3, Python’s own package download and management module (conda in Anaconda), but much more powerful. It can be easily understood as a repository filled with various Python third-party toolkits, similar to our own Maven

1) installation Anaconda

When Anaconda is installed, type the following command to indicate that Anaconda is successfully installed

O_O [cris @ cris: ~] $conda - V conda 4.5.11 ^_^ cris @ cris: ~ $Copy the code

This version of Anaconda comes with version 3.7 of the Python interpreter, the default Base virtual environment, and comes with a number of packages to work with

^_^[cris@cris:~]$ conda list
Copy the code

View the packages in the current Base environment

② What is Base virtual environment?

Anaconda is a repository that currently comes with Anaconda by default. In this repository are many Python third-party packages that come with Anaconda, including the Python interpreter (version 3.7)

In real development, each Python project relies on different packages and may have different versions of the Python interpreter; Each Python project may be developed by one person, or by multiple people; In order to ensure that the Python interpreter and project dependencies are independent and non-interfering with each other, and that the development environment of all Python projects is consistent, Anaconda can configure the Python development and running environment for each project separately. This is the virtual environment in Anaconda.

③ Create Anaconda virtual environment

Run the conda create -n your_env_name python=X.X (2.7, 3.6, etc.) command to create a virtual environment whose python version is X.X and name is your_env_name. The your_env_name file can be found under the envs file in the Anaconda installation directory. If the Python version is 2.7, specify the Python version or the package to be installed. If the Python version is not specified, the system automatically installs the latest Python version.

^_^[cris@cris:~]$conda create -n test python=3.6Copy the code

Then view all of the virtual environments currently in Anaconda

The test virtual environment is the Anaconda Base environment by default.

④ Switching the environment

(base) O_O[cris@cris:~]$ conda activate test
(test) ^_^[cris@cris:~]$ 
Copy the code

After switching, we enter Python’s Terminal

You can see that the Python version has changed to 3.6

After exiting the terminal, run the conda list command to view the packages in the current Test environment

You can see that there are many, many fewer packages than in the Base environment

⑤ Exit and delete the environment

Exiting the current environment and returning to the default Base environment is simple

Deleting the environment is also simple

Conda remove -n env_name -all conda remove -n env_name -all

⑥ Environment installation package management

  • Install the package for the specified environment (default current environment, usually set to base)
conda install -n <env_name> <package_name>
#The -n or --name arguments are used to specify the environment
Copy the code
  • Current environment installation package
conda install <package_name>
Copy the code
  • Deletes the package for the specified environment
conda remove -n <env_name> <package_name>
Copy the code
  • Delete packages for the current environment
conda remove <package_name>
Copy the code
  • Update the package for the current environment
conda update <package_name>
Copy the code
  • Update all packages in the current environment
(base) O_O[cris@cris:~]$ conda update --all
Copy the code
  • Updates multiple specified packages in the current environment. The package names are separated by Spaces and arranged backwards. For example, conda update pandas numpy matplotlib updates the pandas, numpy, and matplotlib packages.

  • Update Conda and keep conda up to date

    conda update conda
    Copy the code
  • Update the anaconda

    conda update anaconda 
    Copy the code
  • To find the package

    conda search package_name
    # conda search numpy
    Copy the code

⑦ Environment replication and export

conda create --name new_env_name --clone copied_env_name
Copy the code

The configuration of the replicated new environment is the same as that of the original environment

Example Export the configuration information of the current environment

(test) ^_^[cris@cris:~]$ conda env export > environment.yaml
Copy the code

An extra configuration file was found in the current directory. Procedure

Look at this file, which is all the configuration information for our current Test environment

name: test channels: - defaults dependencies: -ca-certificates =2018.03.07=0 - Certifi =2018.11.29= PY36_0-libedit =3.1.20170329= H6B74FDF_2-libffi =3.2.1= HD88CF55_4 - Libgcc-ng =8.2.0= hdF63C60_1-libstdcxx-ng =8.2.0= hdF63C60_1-ncurses =6.1= HE6710b0_1 - openSSL =1.1.1a= H7B6447C_0 - PIP =18.1= PY36_0 - python=3.6.8= H0371630_0 - readline=7.0= H7B6447C_5 - setupTools =40.6.3= PY36_0 - Sqlite =3.26.0= H7B6447C_0-TK =8.6.8= HBC83047_0-wheel =0.32.3= PY36_0-xz =5.2.4= H14C39754-zlib =1.2.11= H7B6447C_3 prefix: /home/cris/module/anaconda3/envs/testCopy the code

This way you can quickly set up a unified environment on someone else’s computer

#// Create a new virtual environment with the configuration file
$ conda env create -f environment.yaml
Copy the code

Refer to the blog

Refer to the article

8 Anaconda and Visual Studio Code docking

Open Visual Studio Code and adjust the environment in which Python is run

⑨ Anaconda connects to PyCharm

It’s a little bit more complicated. We have to build a new project

Then select the Anaconda environment

Once the project is created, open the Project option

PyCharm {Inotify Watches Limit} PyCharm {Inotify Watches Limit} PyCharm {Inotify Watches Limit} PyCharm {Inotify Watches LimitSolution link, just do it

** PS: For free activation of PyCharm, see **

⑩ Let Anaconda fly

Anaconda default use of foreign mirror website, here strongly recommended to change the mirror source into the mirror of Tsinghua University

Make your Anaconda run faster than Usain Bolt

Note that the modification paths are in the root directory, and the latest version of Anaconda uses conda info to view the current configuration information as follows

^_^[cris@cris:~]$ conda info

     active environment : base
    active env location : /home/cris/module/anaconda3
            shell level : 1
       user config file : /home/cris/.condarc
 populated config files : /home/cris/.condarc
          conda version : 4.5.11
    conda-build version : 3.15.1
         python version : 3.7.0.final.0
       base environment : /home/cris/module/anaconda3  (writable)
           channel URLs : https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/linux-64
                          https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/noarch
          package cache : /home/cris/module/anaconda3/pkgs
                          /home/cris/.conda/pkgs
       envs directories : /home/cris/module/anaconda3/envs
                          /home/cris/.conda/envs
               platform : linux-64
             user-agent : conda/4.5.11 requests/2.19.1 CPython/3.7.0 Linux/4.15.0-29deepin-generic deepin/15.8 glibc/2.27
                UID:GID : 1000:1000
             netrc file : None
           offline mode : False

Copy the code

2.3 Using the Jupyter Notebook

The use of Jupyter Notebook to complete the test and development of scientific computing has become the mainstream. Here is a brief introduction about the use of Jupyter Notebook

See Blog 1

Reference Blog 2

shortcuts

Shortcut key Reference

The specific use is very simple, in the command line mode, press the H key to display the shortcut key list, and are also explained in Chinese, praise!

The specific shortcut keys are not described here, if you can’t remember, press H

The Jupyter Notebook plug-in is extended

The Jupyter Notebook plug-in management package must be installed

(base) C:\Users\cris>conda install -c conda-forge jupyter_contrib_nbextensions
Copy the code

Then restart the Jupyter Notebook

You can refer to the two blogs above, which document the problems encountered with the Cris plug-in

If formatting plug-ins cannot be used in the newly created virtual environment, you need to import the downloaded plug-ins from the Base environment in the virtual environment

(test) C:\Users\cris>conda install yapf
Copy the code

Please execute the above command in the base environment first, then you can use the code formatting command in the test environment

CTRL + L Current cell formatting code, Shift + CTRL + L Global cell formatting code

To be continued…