From 6a6c53b7d605b13c91ba92f86d8a4575c1600401 Mon Sep 17 00:00:00 2001 From: Courtney Webster Date: Fri, 20 Jan 2023 13:43:56 -0600 Subject: [PATCH 1/7] Updates to Python Tutorial v2 Providing updates to the Python tutorial page. --- docs/python/python-tutorial.md | 58 ++++++++++++++++------------------ 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/docs/python/python-tutorial.md b/docs/python/python-tutorial.md index 5709a77cd2..b411ff6d19 100644 --- a/docs/python/python-tutorial.md +++ b/docs/python/python-tutorial.md @@ -4,15 +4,15 @@ Area: python TOCTitle: Tutorial ContentId: 77828f36-ae45-4887-b25c-34545edd52d3 PageTitle: Get Started Tutorial for Python in Visual Studio Code -DateApproved: 8/15/2022 +DateApproved: 1/20/2023 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) MetaSocialImage: images/tutorial/social.png --- # Getting Started with Python in VS Code -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). +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). -This tutorial introduces you to VS Code as a Python environment, primarily how to edit, run, and debug code through the following tasks: +This tutorial introduces you to VS Code as a Python environment - primarily how to edit, run, and debug code through the following tasks: - Write, run, and debug a Python "Hello World" Application - 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 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. ->**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). +>**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?hl=en-us&gl=us&publisher=Python%20Software%20Foundation). 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) @@ -85,7 +85,9 @@ If the installation was successful, the output window should show the version of > **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 (*). -## Start VS Code in a project (workspace) folder +## Start VS Code in a workspace folder + +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. 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: @@ -97,13 +99,12 @@ code . >**Note**: If you're using an Anaconda distribution, be sure to use an Anaconda command prompt. -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. Alternately, you can run VS Code through the operating system UI, then use **File > Open Folder** to open the project folder. ## Select a Python interpreter -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. +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. 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): @@ -252,36 +253,33 @@ A best practice among Python developers is to avoid installing packages into a g > **Note**: For additional information about virtual environments, see [Environments](/docs/python/environments.md#creating-environments). -1. Create and activate the virtual environment +1. Create a Virtual Environment using the Create Environment Command - **Virtual environment creation for Windows** + From within VS Code, you can create non-global environments, using Venv or Anaconda, by opening the Command Palette (Ctrl+Shift+P), 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. - ```bat - py -3 -m venv .venv - .venv\scripts\activate - ``` + The command presents a list of environment types, Venv or Conda. - If the activate command generates the message "Activate.ps1 is not digitally signed. You cannot run this script on the - current system.", then you need to temporarily change the PowerShell execution policy to allow scripts to - run (see [About Execution Policies](https://go.microsoft.com/fwlink/?LinkID=135170) in the PowerShell documentation): + ![Create Environment dropdown](images/environments/create_environment_dropdown.png) - ```powershell - Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process - ``` + If you are creating an environment using **Venv**, the command presents a list of interpreters that can be used for your project. - **Virtual environment creation for macOS/Linux** + ![Virtual environment interpreter selection](images/environments/interpreters-list.png) - ```bash - python3 -m venv .venv - source .venv/bin/activate - ``` - >**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. + If you are creating an environment using **Conda**, the command presents a list of Python versions that can be used for your project. + + ![Conda environment Python version selection](images/environments/conda_environment_python_versions.png) + + After selecting the desired interpreter or Python version, a notification will show the progress of the environment creation and the environment folder will appear in your workspace. + + ![Create environment status notification](images/environments/create_environment_prompt_status.png) + + 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. - ![Virtual environment dialog](images/tutorial/virtual-env-dialog.png) + > **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. +1. Ensure your new environment is selected by using the **Python: Select Interpreter** command from the **Command Palette**. -1. Select your new environment by using the **Python: Select Interpreter** command from the **Command Palette**. -![Select an Interpreter](images/tutorial/interpreter-venv.png) + ![Select an Interpreter](images/tutorial/interpreter-venv.png) 1. Install the packages ```bash @@ -324,5 +322,5 @@ There is then much more to explore with Python in Visual Studio Code: - [Debugging](/docs/python/debugging.md) - Learn to debug Python both locally and remotely. - [Testing](/docs/python/testing.md) - Configure test environments and discover, run, and debug tests. - [Settings reference](/docs/python/settings-reference.md) - Explore the full range of Python-related settings in VS Code. -- [Deploy Python to Azure App Service using containers](https://learn.microsoft.com/azure/developer/python/tutorial-deploy-containers-01) -- [Deploy Python to Azure App Service on Linux](https://learn.microsoft.com/azure/developer/python/configure-python-web-app-local-environment) +- [Deploy Python to Azure App Service](https://learn.microsoft.com/en-us/azure/developer/python/tutorial-containerize-deploy-python-web-app-azure-01) +- [Deploy Python to Container Apps](https://learn.microsoft.com/en-us/azure/developer/python/tutorial-deploy-python-web-app-azure-container-apps-01) From 20ba2fbc289d7a02bcc54981c3c43bb7ed38e774 Mon Sep 17 00:00:00 2001 From: Greg Van Liew Date: Fri, 20 Jan 2023 14:02:54 -0800 Subject: [PATCH 2/7] Small edits --- docs/python/python-tutorial.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/python/python-tutorial.md b/docs/python/python-tutorial.md index b411ff6d19..60becbb120 100644 --- a/docs/python/python-tutorial.md +++ b/docs/python/python-tutorial.md @@ -45,7 +45,7 @@ Along with the Python extension, you need to install a Python interpreter. Which 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. ->**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?hl=en-us&gl=us&publisher=Python%20Software%20Foundation). +>**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). 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) @@ -255,7 +255,7 @@ A best practice among Python developers is to avoid installing packages into a g 1. Create a Virtual Environment using the Create Environment Command - From within VS Code, you can create non-global environments, using Venv or Anaconda, by opening the Command Palette (Ctrl+Shift+P), 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. + 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. The command presents a list of environment types, Venv or Conda. @@ -273,7 +273,7 @@ A best practice among Python developers is to avoid installing packages into a g ![Create environment status notification](images/environments/create_environment_prompt_status.png) - 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. + 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. > **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. @@ -322,5 +322,5 @@ There is then much more to explore with Python in Visual Studio Code: - [Debugging](/docs/python/debugging.md) - Learn to debug Python both locally and remotely. - [Testing](/docs/python/testing.md) - Configure test environments and discover, run, and debug tests. - [Settings reference](/docs/python/settings-reference.md) - Explore the full range of Python-related settings in VS Code. -- [Deploy Python to Azure App Service](https://learn.microsoft.com/en-us/azure/developer/python/tutorial-containerize-deploy-python-web-app-azure-01) -- [Deploy Python to Container Apps](https://learn.microsoft.com/en-us/azure/developer/python/tutorial-deploy-python-web-app-azure-container-apps-01) +- [Deploy Python to Azure App Service](https://learn.microsoft.com/azure/developer/python/tutorial-containerize-deploy-python-web-app-azure-01) +- [Deploy Python to Container Apps](https://learn.microsoft.com/azure/developer/python/tutorial-deploy-python-web-app-azure-container-apps-01) From 3b524d223e16cb75e31b827dc6c3f916cac2ab21 Mon Sep 17 00:00:00 2001 From: Courtney Webster <60238438+cwebster-99@users.noreply.github.com> Date: Tue, 24 Jan 2023 15:19:45 -0600 Subject: [PATCH 3/7] Update docs/python/python-tutorial.md --- docs/python/python-tutorial.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/python/python-tutorial.md b/docs/python/python-tutorial.md index 60becbb120..ac8e768d60 100644 --- a/docs/python/python-tutorial.md +++ b/docs/python/python-tutorial.md @@ -269,7 +269,7 @@ A best practice among Python developers is to avoid installing packages into a g ![Conda environment Python version selection](images/environments/conda_environment_python_versions.png) - After selecting the desired interpreter or Python version, a notification will show the progress of the environment creation and the environment folder will appear in your workspace. + After selecting the desired interpreter, a notification will show the progress of the environment creation and the environment folder will appear in your workspace. ![Create environment status notification](images/environments/create_environment_prompt_status.png) From 5b3cf16e2744b1d922cbee2cb7766b6835a13347 Mon Sep 17 00:00:00 2001 From: Courtney Webster <60238438+cwebster-99@users.noreply.github.com> Date: Tue, 24 Jan 2023 15:19:53 -0600 Subject: [PATCH 4/7] Update docs/python/python-tutorial.md --- docs/python/python-tutorial.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/python/python-tutorial.md b/docs/python/python-tutorial.md index ac8e768d60..12cd212c68 100644 --- a/docs/python/python-tutorial.md +++ b/docs/python/python-tutorial.md @@ -267,7 +267,6 @@ A best practice among Python developers is to avoid installing packages into a g If you are creating an environment using **Conda**, the command presents a list of Python versions that can be used for your project. - ![Conda environment Python version selection](images/environments/conda_environment_python_versions.png) After selecting the desired interpreter, a notification will show the progress of the environment creation and the environment folder will appear in your workspace. From f23ef30bc6663a274e887daf614d4ddc917584f8 Mon Sep 17 00:00:00 2001 From: Courtney Webster <60238438+cwebster-99@users.noreply.github.com> Date: Tue, 24 Jan 2023 15:19:59 -0600 Subject: [PATCH 5/7] Update docs/python/python-tutorial.md --- docs/python/python-tutorial.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/python/python-tutorial.md b/docs/python/python-tutorial.md index 12cd212c68..86dc492b7e 100644 --- a/docs/python/python-tutorial.md +++ b/docs/python/python-tutorial.md @@ -257,7 +257,7 @@ A best practice among Python developers is to avoid installing packages into a g 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. - The command presents a list of environment types, Venv or Conda. + The command presents a list of environment types, Venv or Conda. For this example, select **Venv**. ![Create Environment dropdown](images/environments/create_environment_dropdown.png) From 5813060804f5c0c8bfb26148b3adb58d76014326 Mon Sep 17 00:00:00 2001 From: Courtney Webster <60238438+cwebster-99@users.noreply.github.com> Date: Tue, 24 Jan 2023 15:20:07 -0600 Subject: [PATCH 6/7] Update docs/python/python-tutorial.md --- docs/python/python-tutorial.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/python/python-tutorial.md b/docs/python/python-tutorial.md index 86dc492b7e..4227734054 100644 --- a/docs/python/python-tutorial.md +++ b/docs/python/python-tutorial.md @@ -261,7 +261,7 @@ A best practice among Python developers is to avoid installing packages into a g ![Create Environment dropdown](images/environments/create_environment_dropdown.png) - If you are creating an environment using **Venv**, the command presents a list of interpreters that can be used for your project. + The command then presents a list of interpreters that can be used for your project. ![Virtual environment interpreter selection](images/environments/interpreters-list.png) From 2fa34309447f849a6c1a533eaf046b147131abd4 Mon Sep 17 00:00:00 2001 From: Courtney Webster <60238438+cwebster-99@users.noreply.github.com> Date: Tue, 24 Jan 2023 15:20:14 -0600 Subject: [PATCH 7/7] Update docs/python/python-tutorial.md --- docs/python/python-tutorial.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/python/python-tutorial.md b/docs/python/python-tutorial.md index 4227734054..2597c4ee06 100644 --- a/docs/python/python-tutorial.md +++ b/docs/python/python-tutorial.md @@ -265,7 +265,6 @@ A best practice among Python developers is to avoid installing packages into a g ![Virtual environment interpreter selection](images/environments/interpreters-list.png) - If you are creating an environment using **Conda**, the command presents a list of Python versions that can be used for your project. After selecting the desired interpreter, a notification will show the progress of the environment creation and the environment folder will appear in your workspace.