You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/python/python-tutorial.md
+26-30Lines changed: 26 additions & 30 deletions
Original file line number
Diff line number
Diff line change
@@ -4,15 +4,15 @@ Area: python
4
4
TOCTitle: Tutorial
5
5
ContentId: 77828f36-ae45-4887-b25c-34545edd52d3
6
6
PageTitle: Get Started Tutorial for Python in Visual Studio Code
7
-
DateApproved: 8/15/2022
7
+
DateApproved: 1/20/2023
8
8
MetaDescription: A Python hello world tutorial using the Python extension in Visual Studio Code (a great Python IDE like PyCharm, if not the best Python IDE)
9
9
MetaSocialImage: images/tutorial/social.png
10
10
---
11
11
# Getting Started with Python in VS Code
12
12
13
-
In this tutorial, you use Python 3 to create the simplest Python "Hello World" application in Visual Studio Code. By using the Python extension, you make VS Code into a great lightweight Python IDE (which you may find a productive alternative to PyCharm).
13
+
In this tutorial, you will use Python 3 to create the simplest Python "Hello World" application in Visual Studio Code. By using the Python extension, you make VS Code into a great lightweight Python IDE (which you may find a productive alternative to PyCharm).
14
14
15
-
This tutorial introduces you to VS Code as a Python environment, primarily how to edit, run, and debug code through the following tasks:
15
+
This tutorial introduces you to VS Code as a Python environment - primarily how to edit, run, and debug code through the following tasks:
16
16
17
17
- Write, run, and debug a Python "Hello World" Application
18
18
- Learn how to install packages by creating Python virtual environments
@@ -45,7 +45,7 @@ Along with the Python extension, you need to install a Python interpreter. Which
45
45
46
46
Install [Python from python.org](https://www.python.org/downloads/). You can typically use the **Download Python** button that appears first on the page to download the latest version.
47
47
48
-
>**Note**: If you don't have admin access, an additional option for installing Python on Windows is to use the Microsoft Store. The Microsoft Store provides installs of [Python 3.7](https://www.microsoft.com/p/python-37/9nj46sx7x90p), [Python 3.8](https://www.microsoft.com/p/python-38/9mssztt1n39l), [Python 3.9](https://www.microsoft.com/p/python-39/9p7qfqmjrfp7), and [Python 3.10](https://www.microsoft.com/p/python-310/9pjpw5ldxlz5).
48
+
>**Note**: If you don't have admin access, an additional option for installing Python on Windows is to use the Microsoft Store. The Microsoft Store provides installs of [supported Python versions](https://apps.microsoft.com/store/search?publisher=Python%20Software%20Foundation).
49
49
50
50
For additional information about using Python on Windows, see [Using Python on Windows at Python.org](https://docs.python.org/3.9/using/windows.html)
51
51
@@ -85,7 +85,9 @@ If the installation was successful, the output window should show the version of
85
85
86
86
>**Note** You can use the `py -0`commandin the VS Code integrated terminal to view the versions of python installed on your machine. The default interpreter is identified by an asterisk (*).
87
87
88
-
## Start VS Code in a project (workspace) folder
88
+
## Start VS Code in a workspace folder
89
+
90
+
By starting VS Code in a folder, that folder becomes your "workspace". VS Code stores settings that are specific to that workspace in`.vscode/settings.json`, which are separate from user settings that are stored globally.
89
91
90
92
Using a command prompt or terminal, create an empty folder called "hello", navigate into it, and open VS Code (`code`) in that folder (`.`) by entering the following commands:
91
93
@@ -97,13 +99,12 @@ code .
97
99
98
100
>**Note**: If you're using an Anaconda distribution, be sure to use an Anaconda command prompt.
99
101
100
-
By starting VS Code in a folder, that folder becomes your "workspace". VS Code stores settings that are specific to that workspace in `.vscode/settings.json`, which are separate from user settings that are stored globally.
101
102
102
103
Alternately, you can run VS Code through the operating system UI, then use **File > Open Folder** to open the project folder.
103
104
104
105
## Select a Python interpreter
105
106
106
-
Python is an interpreted language, and in order to run Python code and get Python IntelliSense, you must tell VS Code which interpreter to use.
107
+
Python is an interpreted language. Thus, in order to run Python code and get Python IntelliSense, you must tell VS Code which interpreter to use.
107
108
108
109
From within VS Code, select a Python 3 interpreter by opening the **Command Palette** (`kb(workbench.action.showCommands)`), start typing the **Python: Select Interpreter** command to search, then select the command. You can also use the **Select Python Environment** option on the Status Bar if available (it may already show a selected interpreter, too):
109
110
@@ -252,36 +253,31 @@ A best practice among Python developers is to avoid installing packages into a g
252
253
253
254
>**Note**: For additional information about virtual environments, see [Environments](/docs/python/environments.md#creating-environments).
254
255
255
-
1. Create and activate the virtual environment
256
+
1. Create a Virtual Environment using the Create Environment Command
256
257
257
-
**Virtual environment creation for Windows**
258
+
From within VS Code, you can create non-global environments, using Venv or Anaconda, by opening the Command Palette (`kb(workbench.action.showCommands)`), start typing the **Python: Create Environment**command to search, and thenselectthe command. You can also trigger the **Python: Create Environment**command through the Getting Started with Python page.
258
259
259
-
```bat
260
-
py -3 -m venv .venv
261
-
.venv\scripts\activate
262
-
```
260
+
The command presents a list of environment types, Venv or Conda. For this example, select**Venv**.
263
261
264
-
If the activate command generates the message "Activate.ps1 is not digitally signed. You cannot run this script on the
265
-
current system.", then you need to temporarily change the PowerShell execution policy to allow scripts to
266
-
run (see [About Execution Policies](https://go.microsoft.com/fwlink/?LinkID=135170) in the PowerShell documentation):
>**Note**: When you create a new virtual environment, you should be prompted by VS Code to set it as the default for your workspace folder. If selected, the environment will automatically be activated when you open a new terminal.
After selecting the desired interpreter, a notification will show the progress of the environment creation and the environment folder will appear in your workspace.
271
+
272
+

273
+
274
+
The command will also install necessary packages outlined in a requirements/dependencies file, such as `requirements.txt`, `pyproject.toml`, or `environment.yml`, located in the project folder.
275
+
276
+
>**Note**: If you want to create an environment manually, or run into error in the environment creation process, visit the [Environments](/docs/python/environments.md#create-a-virtual-environment-in-the-terminal) page.
277
+
278
+
1. Ensure your new environment is selected by using the **Python: Select Interpreter**command from the **Command Palette**.
282
279
283
-
1. Select your new environment by using the **Python: Select Interpreter**command from the **Command Palette**.
284
-

280
+

285
281
1. Install the packages
286
282
287
283
```bash
@@ -324,5 +320,5 @@ There is then much more to explore with Python in Visual Studio Code:
324
320
- [Debugging](/docs/python/debugging.md) - Learn to debug Python both locally and remotely.
325
321
- [Testing](/docs/python/testing.md) - Configure test environments and discover, run, and debug tests.
326
322
- [Settings reference](/docs/python/settings-reference.md) - Explore the full range of Python-related settings in VS Code.
327
-
- [Deploy Python to Azure App Service using containers](https://learn.microsoft.com/azure/developer/python/tutorial-deploy-containers-01)
328
-
- [Deploy Python to Azure App Service on Linux](https://learn.microsoft.com/azure/developer/python/configure-python-web-app-local-environment)
323
+
- [Deploy Python to Azure App Service](https://learn.microsoft.com/azure/developer/python/tutorial-containerize-deploy-python-web-app-azure-01)
324
+
- [Deploy Python to Container Apps](https://learn.microsoft.com/azure/developer/python/tutorial-deploy-python-web-app-azure-container-apps-01)
0 commit comments