Article directory
Preface
Running python code requires 2 software as follows:
Anaconda: used to create virtual environments. Different python environments can be created at the same time. Multiple virtual environments are isolated from each other so that they are not Influence each other.
VScode: Code editor for writing and running code, not only python, but also C, C++, Java, JS, etc.
software download
Anaconda download
Anaconda:https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/?C=M&O=D
Download from the above Tsinghua mirror, click on date sorting, you can install the latest version, as shown in the figure below. For Windows systems, download windows X86_64. Other system versions can be downloaded by yourself.
VScode download
Vscode:https://code.visualstudio.com/download
Click the above link to download VScode, as shown in the picture below, download the windows version.
Software Installation
Anaconda installation
Select next, I agree, next, and choose the D drive for the installation path.
It is more important to go to the picture below. Check the first one, so that it will be added to the environment variable occupation. It doesn't matter if the font turns red. If you don't add it to the environment variable, you have to add it manually, which is more troublesome. (Except for this step, everything else can be left to default)
Then select install to install.
Vscod installation
Double-click the installation, agree to the agreement and next step, select the installation path as you like, next step,
At the next step, for convenience, check all the boxes. Then install.
Configure the virtual environment and run the code
Anaconda creates environment
Press Win+R on the keyboard, enter CMD to open the terminal, enter activate base to activate the base environment, as shown below. The word (base) will appear on the command line.
Create a new virtual environment, command: conda create -n env python=3.9
-n in the above command represents name, and env is the name of the created virtual environment. You can also change it to any other letters at will, such as test, torch, tf, etc., but it is generally not recommended to use Chinese naming.
python=3.9 represents version 3.9. You can also install other versions equal to 3.8 or 3.10.
Jump out of the following interface, select y, and then click enter to continue.
After installation, as shown below, command: activate env
Activate the newly created env virtual environment, and env will appear in front.
If you only use the python command, you have created a virtual environment of version 3.9. You can jump to how to use VScode.
If you want to use it for deep learning, you can pip install some commands in the env environment, such as pandas, numpy, tqdm, torch, etc.
Use VScode to run the code
1. Open the folder where the code is located
Open VScode, if it is English, follow the steps below to install the Simplified Chinese plug-in, then a restart will pop up, and then the restart will be Chinese.
Click File, open the folder, and select the folder where the python code is located.
Then find the python code and click to open it. If you feel that the font is small, hold down ctrl without letting go, and then click on the "+/=" sign on the keyboard to enlarge the font.
2. Select an interpreter
Select the interpreter as shown below
Then open the image below and select your own env environment. As shown below, look for the line with env in brackets.
After selecting the interpreter, the lower right corner will change to env: conda.
3. Run the code
Run the python file as shown below.
At this time, the code result will be output, as shown below.
Summarize
By reading this article, you can learn how to download anaconda and VScode software, install these two software, use anaconda to create a virtual environment, select conda's interpreter through VScode, and finally run the code.