Programming Language: python
Integrated Development Environment (IDE): Visual Studio Code
Table of contents
Identify the Python language
Install the Python plugin (Extensions) in VScode
Explain the Python language
Python is a scripting language that does not need to be compiled . The interpreter is responsible for interpreting it into a machine language that the computer can process.
Download the Python interpreter
Python Official Download Site- Download the latest version for Windows
Install
①Check Add python.exe to PATH, add environment variables
②Choose custom installation
①Checked by default, Python documentation, must be installed
②Checked by default, pip.exe, recommended installation, used to download from PYPI (Python Package Index) Download and install Python third-party packages (packages)
In Python, packages are how you obtain any number of useful code libraries, typically from PyPI.
③The default development environment, the integrated development environment IDLE that comes with Python, is recommended to install
Check if the installation is successful
Open the command prompt (cmd), enter python, press Enter
If the installation is successful and the environment variable has been configured, the python version will be displayed
Reminder: Configure environment variables
If there is a Path variable, click Edit (if not, create a new Path variable)
to create two new paths:
①Python installation path: configure the environment variable of Python.exe
②Python installation path\Scripts: configure the environment variable of pip.exe
Create a program file (.py)
Create a new folder as a Python workspace (WorkSpace) to store Python files
Open the folder in VSCode > File > Open Folder Create
a new Python file (.py) in VSCode > file > New File, and this folder exists middle
Prepare to run the environment
Programs written in the Python language must run in the Python environment, which includes an interpreter and a series of packages.
By default, any Python interpreter installed runs in its own global environment. Any package installed or uninstalled in the global environment affects all programs running in it. Installing too many packages in the global environment can cause all Program runs slowly.
To solve this problem, a virtual environment can be created for each workspace, which will contain a copy of the interpreter, and installing or uninstalling packages in this virtual environment will only affect the programs in the current project.
Create a virtual environment
Ctrl+ Shift+ POpen the command panel (Command Palette), enter Python: Create Environment
Select to create a virtual environment with Venv
Select the interpreter used to create a virtual environment
The above operation is equivalent to entering the following code in Terminal:
python -m venv .venv
After the virtual environment is created, a folder .venv
named
work in a virtual environment
Ctrl+ Shift+ POpen the command panel, enter Python: Select Interpreter
to select the interpreter in the virtual environment, and the virtual environment will be activated (when you open the Python file in this folder with Vscode again, it will run in the last selected environment by default)
The selected interpreter will be displayed in the status bar in the lower right corner of the interface:
The command to activate the virtual environment in Terminal is as follows:
.venv\scripts\activate
The command to close the virtual environment in Terminal is as follows:
deactivate
Install the package using pip
After the virtual environment is created, there will be files under the .venv > Script folder pip.exe
. It is recommended to install the required packages in the virtual environment
Enter the following code in Terminal to update pip to the latest version
python -m pip install --upgrade pip
The display Requirement already satisfied
indicates that pip is already the latest version, as shown in the figure below:
The command to install the package in Terminal is as follows:
python -m pip install xxx