Home>Article>Development Tools> How to run python code in vscode

How to run python code in vscode

hzc
hzc Original
2020-07-03 16:09:06 22232browse

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.

How to run python code in vscode

1. Install the Python plug-in

After entering the main interface, pressCtrl p, enter:ext install python, just download the first one.

After downloading thePythonplug-in, you can use the code auto-completion function when writing Python scripts.

2. Setting upPythonRun

To runPythoninVisual Studio Codethe code needs to be modifiedtasks .json configurationconfiguration code, and to modify thetasks.jsonconfiguration 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.jsonfile in the folder. Therefore, thetasks.jsonfile 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.jsonconfiguration file

Find thetasks.jsonconfiguration file under the .vscode folder and drag it intoVisual Studio Make changes in Code.

You can also directly pressCtrl Shift pand then enter:taskand 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 anyPythonfile in the working folder. UseCtrl Shift bto 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn