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, pressCtrl p
, enter:ext install python
, just download the first one.
After downloading thePython
plug-in, you can use the code auto-completion function when writing Python scripts.
2. Setting upPython
Run
To runPython
inVisual Studio Code
the code needs to be modifiedtasks .json configuration
configuration code, and to modify thetasks.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 thetasks.json
file in the folder. Therefore, thetasks.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 thetasks.json
configuration file
Find thetasks.json
configuration file under the .vscode folder and drag it intoVisual Studio Make changes in Code
.
You can also directly pressCtrl Shift p
and then enter:task
and selectConfigure 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 RunPython
to test anyPython
file in the working folder. UseCtrl 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!