Python3 VSCode configuration

SCode (full name: Visual Studio Code) is a cross-platform free source code editor developed by Microsoft. The VSCode development environment is very simple and easy to use. You only need to install relevant plug-ins for simple configuration, and then you can form a set of development tools with simple code debugging and running with the original python environment. It is friendly to lightweight python development and python learning. Excellent code hints and more plug-in functions make VSCode's experience no less than that of the well-known pythonIDE—pycharm.

Preparation:

  • Install Python 3

  • Install VS Code

  • Install VS Code Python extension and Pylance extension

Install VS Code

The installation of VSCode is relatively simple. Open the official website https://code.visualstudio.com/ , download the software package, and install it step by step. During the installation process, pay attention to the installation path setting, and the environment variables are automatically added to the system by default. Check all the following options:

Install VS Code Python extension and Pylance extension

Then we install the VS Code Python extension:

The Python extension will automatically install the Pylance and Jupyter extensions for the best experience when working with Python files and Jupyter notebooks.

Create a Python code file

Open VScode and click New File:

Click to select language:

Enter Python in the search box and select the Python option:

Enter code:

print("W3Cschool")

Right-click the mouse and choose to run the file in the interactive window. If there is a prompt to install the kernel, just click Install (if there is no installation, it will always be displayed in the connection to the Python kernel): (here VSCode will use python's pip to install, some versions will The installation failed, the editor failed to use the python3.8 version when trying, and the 3.7 version succeeded)

In addition, we can also open an existing file or directory (folder), for example, if we open a python project, you can also create one yourself:

Then we create a test.py file, click the new file icon below, and enter the file name test.py:

注:pythonproject 里面包含了一个 .vscode 文件夹,是一些配置信息,可以先不用管。

在 test.py 输入以下代码:

print("W3Cschool")

点击右上角绿色图标,即可运行:

可以右击文件,选择"在终端中运行 Python 文件":

当然也可以在代码窗口上右击鼠标,选择"在终端中运行 Python 文件"。

Guess you like

Origin blog.csdn.net/m0_67373485/article/details/129743197