Home > Article > Development Tools > How to run python code in vscode
The method for vscode to run python code is: first open vscode and install the plug-in Python; then modify tasks.json in the Python workspace to be run; finally, the shortcut key [Ctrl Shift b] can be used to run it.
1. Install the Python plug-in
After entering the main interface, press Ctrl p
, enter: ext install python
, just download the first one.
After downloading the Python
plug-in, you can use the code auto-completion function when writing Python scripts.
2. Setting up Python
Run
To run Python
in Visual Studio Code
the code needs to be modifiedtasks .json configuration
configuration code, and to modify the tasks.json
configuration code, you must first create a working folder.
To put it simply, different working folders should be oriented to different projects. You can then configure different languages to run by modifying the tasks.json
file in the folder. Therefore, the tasks.json
file will only appear if the working folder is created.
2.1 Create a working folder
Open the resource manager in the main interfaceCtrl Shift E
, click to open the folder, select the folder (there is no available folder, you can open it in the desired folder) Create a new one in the directory).
2.2 Modify the tasks.json
configuration file
Find the tasks.json
configuration file under the .vscode folder and drag it into Visual Studio Make changes in Code
.
You can also directly press Ctrl Shift p
and then enter: task
and select Configure Task Runner.
Choose Others.
Open the file as follows:
Modify the configuration file:
1. Change the "echo" corresponding to the command to "python".
2. The corresponding ["Helloworld"] of args is modified to ["${file}"].
3. Save changes (Ctrl s
).
2.3 Run Python
to test any Python
file in the working folder. Use Ctrl Shift b
to run.
Done!
Recommended tutorial: "VSCode Tutorial"
The above is the detailed content of How to run python code in vscode. For more information, please follow other related articles on the PHP Chinese website!