Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions docs/python/includes/project-from-existing.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,49 @@ Follow these steps to create a project from existing files.

1. In the **Create New Project from Existing Python Code** wizard, set the **Folder path** to your existing code, set a **Filter** for file types, and specify any **Search paths** that your project requires, then select **Next**. If you don't know the search paths, leave the field blank.

::: moniker range="visualstudio"

:::image type="content" source="../media/visualstudio/projects-from-existing-1.png" alt-text="Screenshot of a New Project creation from Existing Code, including choosing the folder path, file type filters, and search paths in Visual Studio." lightbox="../media/visualstudio/projects-from-existing-1.png":::

::: moniker-end

::: moniker range="vs-2022"

:::image type="content" source="../media/projects-from-existing-1.png" alt-text="Screenshot of a New Project creation from Existing Code, including choosing the folder path, file type filters, and search paths." lightbox="../media/projects-from-existing-1.png":::

::: moniker-end

1. On the next page, select the **Startup file** for your project. Visual Studio selects the default global Python interpreter and version. You can change the environment by using the dropdown menu. When you're ready, select **Next**.

> [!NOTE]
> The dialog shows only files in the root folder. If the file you want is in a subfolder, leave the startup file blank. You can set the startup file in **Solution Explorer**, as described in a later step.

::: moniker range="visualstudio"

:::image type="content" source="../media/visualstudio/projects-from-existing-2.png" alt-text="Screenshot of New Project Creation from Existing Code window, including choosing the startup file and Python environment in Visual Studio." lightbox="../media/visualstudio/projects-from-existing-2.png":::

::: moniker-end

::: moniker range="vs-2022"

:::image type="content" source="../media/projects-from-existing-2.png" alt-text="Screenshot of New Project Creation from Existing Code window, including choosing the startup file and Python environment." lightbox="../media/projects-from-existing-2.png":::

::: moniker-end

1. Select the location to store the project file (a _.pyproj_ file on disk). If applicable, you can also include autodetection of virtual environments and customize the project for different web frameworks. If you're unsure of these options, leave the fields set to the defaults.

::: moniker range="visualstudio"

:::image type="content" source="../media/visualstudio/projects-from-existing-3.png" alt-text="Screenshot of a New Project creation from Existing Code window, including the location for the project file and other optional settings in Visual Studio." lightbox="../media/visualstudio/projects-from-existing-3.png":::

::: moniker-end

::: moniker range="vs-2022"

:::image type="content" source="../media/projects-from-existing-3.png" alt-text="Screenshot of a New Project creation from Existing Code window, including the location for the project file and other optional settings." lightbox="../media/projects-from-existing-3.png" :::

::: moniker-end

1. Select **Finish**.

Visual Studio creates the project and opens it in **Solution Explorer**. If you want to move the _.pyproj_ file to a different location, select the file in **Solution Explorer**, and then select **File** > **Save As** on the toolbar. This action updates file references in the project, but it doesn't move any code files.
Expand Down
64 changes: 57 additions & 7 deletions docs/python/managing-python-projects-in-visual-studio.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Manage Python application projects
title: Manage Python Application Projects
description: Explore how projects in Visual Studio manage dependencies between files and the complexity of relationships in an application.
ms.date: 04/18/2024
ms.date: 06/01/2026
ms.topic: how-to
author: Devdiv-VR
ms.author: vedhar
Expand All @@ -15,7 +15,17 @@ ms.subservice: python

Python applications are typically defined by using only folders and files. This structure can become complex as applications grow and perhaps involve autogenerated files, JavaScript for web applications, and so on. A [Visual Studio project](../ide/solutions-and-projects-in-visual-studio.md#projects) can help you manage the complexity. The project (a `.pyproj` file) identifies all the source and content files associated with your project. It contains build information for each file, maintains the information to integrate with source-control systems, and helps you organize your application into logical components.

:::image type="content" source="media/projects-solution-explorer.png" alt-text="Screenshot that shows a Python project open in Solution Explorer in Visual Studio." lightbox="media/projects-solution-explorer.png":::
::: moniker range="visualstudio"

:::image type="content" source="media/visualstudio/projects-solution-explorer.png" alt-text="Screenshot that shows a Python project open in Solution Explorer in Visual Studio." lightbox="media/visualstudio/projects-solution-explorer.png":::

::: moniker-end

::: moniker range="vs-2022"

:::image type="content" source="media/projects-solution-explorer.png" alt-text="Screenshot that shows a Python project open in Solution Explorer." lightbox="media/projects-solution-explorer.png":::

::: moniker-end

Projects are always managed within a [Visual Studio solution](../ide/solutions-and-projects-in-visual-studio.md#solutions). A solution can contain any number of projects that might reference one another, such as a Python project that references a C++ project that implements an extension module. With this relationship, Visual Studio automatically builds the C++ project (if necessary) when you start debugging the Python project. For more information, see [Solutions and projects in Visual Studio](../ide/solutions-and-projects-in-visual-studio.md).

Expand Down Expand Up @@ -53,17 +63,47 @@ If you remove the selected startup file from a project and don't select an alter

A new project is always associated with the default global Python environment. To associate the project with a different environment (including virtual environments), right-click the **Python Environments** node in the project. Select **Add Environment** and then select the environments you want. You can also use the environments drop-down control on the toolbar to select an environment or add another environment to the project.

:::image type="content" source="media/vs-2022/environments-toolbar-2022.png" alt-text="Screenshot that shows the Add Environment command on the Python toolbar in Visual Studio.":::
::: moniker range="visualstudio"

:::image type="content" source="media/visualstudio/environments-toolbar.png" alt-text="Screenshot that shows the Add Environment command in Visual Studio.":::

::: moniker-end

::: moniker range="vs-2022"

:::image type="content" source="media/vs-2022/environments-toolbar-2022.png" alt-text="Screenshot that shows the Add Environment command on the Python toolbar.":::

::: moniker-end

To change the active environment, right-click the desired environment in **Solution Explorer** and select **Activate Environment** as shown in the following image. For more information, see [Select an environment for a project](selecting-a-python-environment-for-a-project.md).

:::image type="content" source="media/vs-2022/projects-activate-environment-2022.png" alt-text="Screenshot that shows how to activate an environment for a Python project in Visual Studio." lightbox="media/vs-2022/projects-activate-environment-2022.png":::
::: moniker range="visualstudio"

:::image type="content" source="media/visualstudio/projects-activate-environment.png" alt-text="Screenshot that shows how to activate an environment for a Python project in Visual Studio." lightbox="media/visualstudio/projects-activate-environment.png":::

::: moniker-end

::: moniker range="vs-2022"

:::image type="content" source="media/vs-2022/projects-activate-environment-2022.png" alt-text="Screenshot that shows how to activate an environment for a Python project." lightbox="media/vs-2022/projects-activate-environment-2022.png":::

::: moniker-end

## Project templates

Visual Studio gives you many ways to set up a Python project, either from scratch or from existing code. To use a template, select **File** > **New** > **Project** or right-click the solution in **Solution Explorer** and select **Add** > **New Project**. In the **new project** dialog, you can see Python-specific templates by searching on *Python* or by selecting the **Language** > **Python** node:

:::image type="content" source="media/projects-new-project-dialog.png" alt-text="Screenshot that shows the new project dialog with available Python templates in Visual Studio." lightbox="media/projects-new-project-dialog.png":::
::: moniker range="visualstudio"

:::image type="content" source="media/visualstudio/projects-new-project-dialog.png" alt-text="Screenshot that shows the new project dialog with available Python templates in Visual Studio." lightbox="media/visualstudio/projects-new-project-dialog.png":::

::: moniker-end

::: moniker range="vs-2022"

:::image type="content" source="media/projects-new-project-dialog.png" alt-text="Screenshot that shows the new project dialog with available Python templates." lightbox="media/projects-new-project-dialog.png":::

::: moniker-end

::: moniker range=">=vs-2022"

Expand Down Expand Up @@ -120,7 +160,17 @@ Linked files can't be renamed.

Visual Studio projects support adding references to projects and extensions, which appear under the **References** node in **Solution Explorer**:

:::image type="content" source="media/projects-extension-references.png" alt-text="Screenshot that shows how to Add an extension reference in Python projects in Visual Studio." lightbox="media/projects-extension-references.png":::
::: moniker range="visualstudio"

:::image type="content" source="media/visualstudio/projects-extension-references.png" alt-text="Screenshot that shows how to Add an extension reference in Python projects in Visual Studio." lightbox="media/visualstudio/projects-extension-references.png":::

::: moniker-end

::: moniker range="vs-2022"

:::image type="content" source="media/projects-extension-references.png" alt-text="Screenshot that shows how to Add an extension reference in Python projects." lightbox="media/projects-extension-references.png":::

::: moniker-end

Extension references typically indicate dependencies between projects and are used to provide IntelliSense at design time or linking at compile time. Python projects use references in a similar fashion, but due to the dynamic nature of Python they're primarily used at design time to provide improved IntelliSense. They can also be used for deployment to Microsoft Azure to install other dependencies.

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.