Introduction to Python Data Analysis (1): Setting up an environment

Python version:

The Python versions used in this course are all 3.x. You must have a certain Python foundation and know the usage of lists, strings, functions, etc.

Python crawler, data analysis, website development and other case tutorial videos are free to watch online

https://space.bilibili.com/523606542 

Python learning exchange group: 1039645993

Anaconda:

Anaconda is a software bundled with Python, conda, and other related dependencies. Contains more than 180 learnable computing packages and their dependencies. Anaconda3 is an environment that integrates Python3, and Anaconda2 is an environment that integrates Python2. The package integrated by Anaconda by default is a package belonging to the built-in Python. And supports most operating systems (such as: Windows, Mac, Linux, etc.). The download address is as follows: https://www.anaconda.com/distribution/ (If the download from the official website is too slow, you can download it from the Tsinghua University open source software site: https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive /). According to your operating system, download the corresponding version. Because Anaconda has many built-in packages, the installation process takes a long time. You need to be patient when installing. After the installation is complete, there will be the following modules: Anaconda prompt, Anaconda Navigator, Spyder, jupyter notebook. Here are some introductions.

Anaconda prompt:

Anaconda prompt is a terminal dedicated to operating anaconda. If you did not add the relevant environment variables to the PATH of the environment variable after installing Anaconda, then you must complete in the Anaconda prompt if you want to use anaconda-related commands in the terminal in the future.

 

Anaconda Navigator:

This is equivalent to a navigation panel on which Anaconda related software is organized.

Spyder:

A software specially developed for Python, students who are familiar with MATLAB will feel more intimate, but in the later learning process, we will not use this tool to write code, because there are better alternative tools.

 

jupyter notebook:

A Python editing environment, you can view the running effect of the code in real time.

 

The posture of using jupyter notebook:

  1. First open Anaconda Prompt, and then enter the directory where the project is located.
  2. Enter the command jupyter notebook to open the jupyter notebook browser.

Basic use of conda:

conda is installed automatically along with the Anaconda installation. Conda can manage different environments like virtualenv, and can also manage packages in a certain environment like pip. Let's take a look at the usage of the two functions.

Environmental management:

Conda can manage different Python environments like virtualenv, and different environments are isolated from each other and do not affect each other. Why do we need to create different environments? The reason is that sometimes there are more projects, but the packages that the projects depend on are different. For example, project A is developed with Python2, and project B is developed with Python3. Then we need two different environments on the same computer. To support them running. The basic commands for creating an environment are as follows:

shell
# conda create --name [环境名称] 比如以下:
conda create --name da-env

This will create an environment called da-env. The python interpreter of this environment is based on anaconda. If anaconda is 3.7, then the 3.7 environment will be used by default, and if the built-in anaconda is 2.7, then the 2.7 environment will be used by default. Then you can use conda install numpy to install the package, and the package installed in this way will only be installed in the current environment. Some students may want to ask, if you want to install a Python2.7 environment, there is no built-in Python2.7 in anaconda, then how to achieve it? . In fact, we only need to specify the python version when installing. If this version does not exist now, anaconda will automatically download it for us. So to install Python2.7 environment, use the following code to achieve:

conda create --name xxx python=2.7

The following lists other commands for conda management environment:

Specify the packages that need to be installed when creating:

 conda create --name xxx numpy pandas

When creating, you need to specify both the package and the python environment:

 conda create --name xxx python=3.6 numpy pandas

Into an environment

 windows: activate xxx mac/linux: source activate xxx

Exit the environment:

 deactivate

List all current environments:

 conda env list

Remove an environment:

 conda remove --name xxx --all

Package export and import under the environment:

Export: conda env export> environment.yml.

导入:conda env create --name xxx -f environment.yml。

Package management:

conda can also be used to manage packages. For example, after we create a new environment, we want to install a package (such as numpy) in this environment, then we can use the following code to achieve:

python
activate xxx
conda install numpy

Here are some commonly used commands for package management:

Install the package directly to this environment without entering an environment:

conda install [包名] -n [环境名]

List all packages in this environment:

 conda list

Uninstall a package:

 conda remove [包名]

Set the source of the installation package:

 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/main/ 
conda config --set show_channel_urls yes

Guess you like

Origin blog.csdn.net/m0_48405781/article/details/114748181