Carrying python programming environment on Linux subsystem (WSL) of win10

Time:2020-10-26

Why use WSL for Python Programming

WSL, full name of windows subsystem for Linux. In short, win10 provides a Linux subsystem, which can solve the problem of separation between virtual machine and dual system system without affecting the application of win10 itself.

For Linux subsystems established on win10, such as Ubuntu, it may bring its own Python compiler, which can compile and run some simple Python scripts.

The command “which Python” can usually check the version and installation location of native python. The installation location is usually located in / usr / bin,

Some other large compilers come with different versions of the compiler when they are installed, so you can use the command “LS / usr / bin / Python *” to view all the python types installed locally.

The way to set Linux subsystem in win10 is as follows:

Under windows, please open WSL and install Ubuntu:

1. Administrator permission to open the PowerShell. In the start menu, enter the PowerShell, right-click windows PowerShell and select administrator permission to run (or press the shortcut key win + R, and then enter CMD to open the command prompt)

2. Copy and copy the following code in the command window or command prompt to open the WSL function:

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

3. Open the Microsoft Store, search for Ubuntu, select Ubuntu and install it. After that, there are three ways to enter the Linux system: first, enter bash in Windows PowerShell; second, enter bash in the command prompt; third, open the Ubuntu application directly.

Why choose python programming environment under Anaconda

Although the above Python compiler can run some. Py files, some packages are not installed, and all files containing numpy / pandas libraries will automatically report errors when compiling.

When installing various packages, sometimes the complex dependency relationship between different packages will make the installation process of a package become the installation of a series of packages. CONDA can solve the problem of path dependence.

In addition, CONDA can also establish some relatively independent programming environments, each of which is an independent project, so as to avoid the mutual pollution between different versions of packages.

Installation method of Anaconda:

1. Download 64 bit installer for Anaconda athttps://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2020.07-Linux-x86_64.sh

2. Change to the download directory, open terminal, and enter the command: “bash anaconda3-2020.07-linux-x86″_ SH “, and then follow the prompt” yes “all the way during the installation.

When you open the terminal, the installation of anaconda is successful. For super user root, CONDA is usually installed in the root directory of “root / Anaconda”. For ordinary users, it is usually installed under the “home / user name / Anaconda”.

The next step is to update the configuration of anaconda. The main function of this step is to update the source. The default foreign source download speed is very slow. There are two ways to change it:

Anaconda configuration update

Method 1: enter the command in (base)

1 conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
2 conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
3 conda config --remove channels defaults
4 conda config --set show_channel_urls yes

If there is a slow download problem in the subsequent software installation, please refer to my next article

Method 2: find the. Condarc file and input the image source

For the root user, enter “Cd ~ /. Condarc”, for the normal user, enter “CD / home / user name /. Condarc” and enter the following command

1 ssl_verify: true
2 
3 channels:
4   - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
5   - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
6 
7 show_channel_urls: true

If the network connection fails in this step, please refer to the solution:https://www.cnblogs.com/liangxuran/p/13507487.html

 

Why create a separate CONDA environment for each project

As mentioned earlier, a stand-alone Python compilation environment rather than base is established to avoid mutual contamination among various package versions.

It is suggested that different environment should be carried out for different projects each time.

How to create / activate / exit independent CONDA environment:

New independent CONDA environment command: “CONDA create — name CONDA_ Name python = 3 “or” CONDA create – n CONDA “_ name_ 01 python=3”

The command to activate the environment: “CONDA activate CONDA_ name_ 01”

Command to exit the environment: “CONDA deactivate”

The command to copy the environment: “CONDA create – n CONDA_ name_ 01 –clone conda_ name_ 02”

Remove the command for the environment: “CONDA remove -n CONDA_ name_ 01 –all”

If the following error is reported, you need to update the source in the. / condarc file. Solution referencehttps://www.cnblogs.com/liangxuran/p/13507487.html

 

The next step is to install some Python packages in this environment to meet the needs of scientific computing

How CONDA installs Python packages:

Install with CONDA: “CONDA install numpy” ා

Install with PIP: “PIP install numpy” ා

My common Python packages are: numpy, pandas, Matplotlib, SciPy, netcdf4, Jupiter, obspy

The first four are relatively popular, and the last three are relatively small.