Skip to content

Commit fa50eec

Browse files
cwebster-99Greg Van Liew
and
Greg Van Liew
authored
Updates to Python Tutorial v2 (#5963)
* Updates to Python Tutorial v2 Providing updates to the Python tutorial page. * Small edits * Update docs/python/python-tutorial.md * Update docs/python/python-tutorial.md * Update docs/python/python-tutorial.md * Update docs/python/python-tutorial.md * Update docs/python/python-tutorial.md Co-authored-by: Greg Van Liew <[email protected]>
1 parent 3e5587d commit fa50eec

File tree

1 file changed

+26
-30
lines changed

1 file changed

+26
-30
lines changed

docs/python/python-tutorial.md

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ Area: python
44
TOCTitle: Tutorial
55
ContentId: 77828f36-ae45-4887-b25c-34545edd52d3
66
PageTitle: Get Started Tutorial for Python in Visual Studio Code
7-
DateApproved: 8/15/2022
7+
DateApproved: 1/20/2023
88
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)
99
MetaSocialImage: images/tutorial/social.png
1010
---
1111
# Getting Started with Python in VS Code
1212

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).
1414

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:
1616

1717
- Write, run, and debug a Python "Hello World" Application
1818
- 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
4545

4646
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.
4747

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).
4949
5050
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)
5151

@@ -85,7 +85,9 @@ If the installation was successful, the output window should show the version of
8585

8686
> **Note** You can use the `py -0` command in the VS Code integrated terminal to view the versions of python installed on your machine. The default interpreter is identified by an asterisk (*).
8787

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.
8991

9092
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:
9193

@@ -97,13 +99,12 @@ code .
9799

98100
>**Note**: If you're using an Anaconda distribution, be sure to use an Anaconda command prompt.
99101
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.
101102
102103
Alternately, you can run VS Code through the operating system UI, then use **File > Open Folder** to open the project folder.
103104
104105
## Select a Python interpreter
105106
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.
107108
108109
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):
109110
@@ -252,36 +253,31 @@ A best practice among Python developers is to avoid installing packages into a g
252253

253254
> **Note**: For additional information about virtual environments, see [Environments](/docs/python/environments.md#creating-environments).
254255

255-
1. Create and activate the virtual environment
256+
1. Create a Virtual Environment using the Create Environment Command
256257

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 then select the command. You can also trigger the **Python: Create Environment** command through the Getting Started with Python page.
258259

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**.
263261

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):
262+
![Create Environment dropdown](images/environments/create_environment_dropdown.png)
267263

268-
```powershell
269-
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process
270-
```
264+
The command then presents a list of interpreters that can be used for your project.
271265

272-
**Virtual environment creation for macOS/Linux**
266+
![Virtual environment interpreter selection](images/environments/interpreters-list.png)
273267

274-
```bash
275-
python3 -m venv .venv
276-
source .venv/bin/activate
277-
```
278-
>**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.
279268

280-
![Virtual environment dialog](images/tutorial/virtual-env-dialog.png)
281269

270+
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+
![Create environment status notification](images/environments/create_environment_prompt_status.png)
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**.
282279

283-
1. Select your new environment by using the **Python: Select Interpreter** command from the **Command Palette**.
284-
![Select an Interpreter](images/tutorial/interpreter-venv.png)
280+
![Select an Interpreter](images/tutorial/interpreter-venv.png)
285281
1. Install the packages
286282

287283
```bash
@@ -324,5 +320,5 @@ There is then much more to explore with Python in Visual Studio Code:
324320
- [Debugging](/docs/python/debugging.md) - Learn to debug Python both locally and remotely.
325321
- [Testing](/docs/python/testing.md) - Configure test environments and discover, run, and debug tests.
326322
- [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

Comments
 (0)