Since releasing Visual Studio 2012 we have continued on our investment in the user experience space to enable you to work more efficiently and to make the Visual Studio experience engaging and productive. One of the design principles we are following is the enablement of choice and personal customization in the product, and as part Read more. Visual Studio 发现更好的软件开发工具 Microsoft Visual Studio。不同版本适用于各种规模的团队,而且还适用于个人开发人员。Visual Studio 2019 是一个全功能的集成开发环境(IDE),适用于 Android、iOS、Windows、web 和云端。.
-->若要安装针对 Visual Studio 的 Python 支持(亦称为“针对 Visual Studio 的 Python 工具 (PTVS)”),请按照 Visual Studio 版本对应部分中的说明操作:To install Python support for Visual Studio (also known as Python Tools for Visual Studio or PTVS), follow the instructions in the section that matches your version of Visual Studio:
若要在执行安装步骤后快速测试 Python 支持,请按 Alt+I 并输入
2+2
打开 Python 交互式窗口 。To quickly test Python support after following the installation steps, open the Python Interactive window by pressing Alt+I and entering 2+2
.如果看不到输出 4
,请重新检查步骤。If you don't see the output of 4
, recheck your steps.提示
Python 工作负载包括有用的 Cookiecutter 扩展,扩展提供图形用户界面以发现模板、输入模板选项及创建项目和文件。The Python workload includes the helpful Cookiecutter extension that provides a graphical user interface to discover templates, input template options, and create projects and files.有关详细信息,请参阅使用 Cookiecutter。For details, see Use Cookiecutter.
备注
目前尚未在 Visual Studio for Mac 中提供 Python 支持,但可在 Mac 和 Linux 上通过 Visual Studio Code 获取相应支持。Python support is not presently available in Visual Studio for Mac, but is available on Mac and Linux through Visual Studio Code.请参阅问题和解答。See questions and answers.
Visual Studio 2019 和 Visual Studio 2017Visual Studio 2019 and Visual Studio 2017
- 下载并运行最新 Visual Studio 安装程序。Download and run the latest Visual Studio installer.如果已安装 Visual Studio,则运行 Visual Studio 安装程序,选择“修改”选项(请参阅修改 Visual Studio),并转到步骤 2 。If you have Visual Studio installed already, run the Visual Studio Installer, select the Modify option (see Modify Visual Studio) and go to step 2.提示Community Edition 适用于个体开发者、课堂学习、学术研究和开放源代码开发。The Community edition is for individual developers, classroom learning, academic research, and open source development.对于其他用途,请安装 Visual Studio 2019 Professional 或 Visual Studio 2019 Enterprise。For other uses, install Visual Studio 2019 Professional or Visual Studio 2019 Enterprise.
- 安装程序提供工作负载列表,即一组用于特定开发领域的相关选项。The installer presents you with a list of workloads, which are groups of related options for specific development areas.对于 Python,请选择 Python 开发工作负载。For Python, select the Python development workload.可选:如果使用数据科学,还可考虑使用数据科学和分析应用程序工作负载。Optional: if you're working with data science, also consider the Data science and analytical applications workload.此工作负载包含 Python、R 和 F# 语言支持。This workload includes support for the Python, R, and F# languages.有关详细信息,请参阅数据科学和分析应用程序工作负载。For more information, see Data science and analytical applications workload.备注Python 和数据科学工作负载仅可用于 Visual Studio 2017 版本 15.2 及更高版本。The Python and Data Science workloads are available only with Visual Studio 2017 version 15.2 and later.可选:如果使用数据科学,还可考虑使用数据科学和分析应用程序工作负载。Optional: if you're working with data science, also consider the Data science and analytical applications workload.此工作负载包含对 Python 和 F# 语言的支持。This workload includes support for the Python and F# languages.有关详细信息,请参阅数据科学和分析应用程序工作负载。For more information, see Data science and analytical applications workload.
- 如果需要,选择安装程序右侧的其他选项。On the right side of the installer, chose additional options if desired.跳过此步骤,接受默认选项。Skip this step to accept the default options.
选项Option 描述Description Python 分发版本Python distributions 选择计划使用的可用选项任意组合,例如 Python 2、Python 3、Miniconda、Anaconda2 和 Anaconda3 分发版本的 32 位和 64 位变体。Choose any combination of the available options, such as 32-bit and 64-bit variants of the Python 2, Python 3, Miniconda, Anaconda2, and Anaconda3 distributions that you plan to work with.每个组合都包含分发版本的解释器、运行时和库。Each includes the distribution's interpreter, runtime, and libraries.具体来说,Anaconda 是开放数据科学平台,包含各种预安装的包。Anaconda, specifically, is an open data science platform that includes a wide range of pre-installed packages.(可随时返回 Visual Studio 安装程序来添加或删除分发版本。)说明:如果已安装 Visual Studio 安装程序之外的分发版本,则无需检查此处的等效选项。(You can return to the Visual Studio installer at any time to add or remove distributions.) Note: If you've installed a distribution outside of the Visual Studio installer, there's no need to check the equivalent option here.Visual Studio 会自动检测现有的 Python 安装。Visual Studio automatically detects existing Python installations.请参阅“Python 环境”窗口。See The Python Environments window.此外,若有比安装程序中所显示的版本更高的 Python 版本可用,可以单独安装较高版本,并且 Visual Studio 会检测到它。Also, if a newer version of Python is available than what's shown in the installer, you can install that version separately and Visual Studio will detect it. Cookiecutter 模板支持Cookiecutter template support 安装 Cookiecutter 图形用户界面,用于发现模板、输入模板选项以及创建项目和文件。Installs the Cookiecutter graphical UI to discover templates, input template options, and create projects and files.请参阅使用 Cookiecutter 扩展。See Use the Cookiecutter extension. Python Web 支持Python web support 安装用于 Web 开发的工具(包括 HTML、CSS 和 JavaScript 编辑支持)以及用于使用 Bottle、Flask 和 Django 框架的项目的模板。Installs tools for web development including HTML, CSS, and JavaScript editing support, along with templates for projects using the Bottle, Flask, and Django frameworks.请参阅 Python Web 项目模板。See Python web project templates. Python IoT 支持Python IoT support 支持使用 Python 开发 Windows IoT Core。Supports Windows IoT Core development using Python. Python 本机开发工具Python native development tools 安装 C++ 编译器和其他必要组件用于开发 Python 本机扩展。Installs the C++ compiler and other necessary components to develop native extensions for Python.请参阅创建适用于 Python 的 C++ 扩展。See Create a C++ extension for Python.若要获取全面的 C++ 支持,还请安装“使用 C++ 的桌面开发” 工作负载。Also install the Desktop development with C++ workload for full C++ support. Azure 云服务核心工具Azure Cloud Services core tools 提供在 Python 中开发 Azure 云服务的其他支持。Provides additional support for developer Azure Cloud Services in Python.请参阅 Azure 云服务项目。See Azure cloud service projects. 选项Option 描述Description Python 分发版本Python distributions 选择计划使用的可用选项任意组合,例如 Python 2、Python 3、Miniconda、Anaconda2 和 Anaconda3 分发版本的 32 位和 64 位变体。Choose any combination of the available options, such as 32-bit and 64-bit variants of the Python 2, Python 3, Miniconda, Anaconda2, and Anaconda3 distributions that you plan to work with.每个组合都包含分发版本的解释器、运行时和库。Each includes the distribution's interpreter, runtime, and libraries.具体来说,Anaconda 是开放数据科学平台,包含各种预安装的包。Anaconda, specifically, is an open data science platform that includes a wide range of pre-installed packages.(可随时返回 Visual Studio 安装程序来添加或删除分发版本。)说明:如果已安装 Visual Studio 安装程序之外的分发版本,则无需检查此处的等效选项。(You can return to the Visual Studio installer at any time to add or remove distributions.) Note: If you've installed a distribution outside of the Visual Studio installer, there's no need to check the equivalent option here.Visual Studio 会自动检测现有的 Python 安装。Visual Studio automatically detects existing Python installations.请参阅“Python 环境”窗口。See The Python Environments window.此外,若有比安装程序中所显示的版本更高的 Python 版本可用,可以单独安装较高版本,并且 Visual Studio 会检测到它。Also, if a newer version of Python is available than what's shown in the installer, you can install that version separately and Visual Studio will detect it. Cookiecutter 模板支持Cookiecutter template support 安装 Cookiecutter 图形用户界面,用于发现模板、输入模板选项以及创建项目和文件。Installs the Cookiecutter graphical UI to discover templates, input template options, and create projects and files.请参阅使用 Cookiecutter 扩展。See Use the Cookiecutter extension. Python Web 支持Python web support 安装用于 Web 开发的工具(包括 HTML、CSS 和 JavaScript 编辑支持)以及用于使用 Bottle、Flask 和 Django 框架的项目的模板。Installs tools for web development including HTML, CSS, and JavaScript editing support, along with templates for projects using the Bottle, Flask, and Django frameworks.请参阅 Python Web 项目模板。See Python web project templates. Python 本机开发工具Python native development tools 安装 C++ 编译器和其他必要组件用于开发 Python 本机扩展。Installs the C++ compiler and other necessary components to develop native extensions for Python.请参阅创建适用于 Python 的 C++ 扩展。See Create a C++ extension for Python.若要获取全面的 C++ 支持,还请安装“使用 C++ 的桌面开发” 工作负载。Also install the Desktop development with C++ workload for full C++ support. Azure 云服务核心工具Azure Cloud Services core tools 提供在 Python 中开发 Azure 云服务的其他支持。Provides additional support for developer Azure Cloud Services in Python.请参阅 Azure 云服务项目。See Azure cloud service projects. - 安装后,安装程序会提供用于修改、启动、修复或卸载 Visual Studio 的选项。After installation, the installer provides options to modify, launch, repair, or uninstall Visual Studio.当已安装的所有组件均可使用 Visual Studio 更新时,“修改”按钮将更改为“更新” 。The Modify button changes to Update when updates to Visual Studio are available for any installed components.(随后在下拉菜单中提供“修改”选项。 )还可搜索“Visual Studio”,从 Windows “开始”菜单启动 Visual Studio 及安装程序 。(The Modify option is then available on the drop-down menu.) You can also launch Visual Studio and the installer from the Windows Start menu by searching on 'Visual Studio'.
疑难解答Troubleshooting
如果在 Visual Studio 中安装或运行 Python 时遇到问题,请尝试以下操作:If you encounter problems installing or running Python in Visual Studio, try the following:
- 确定使用 Python CLI(即在命令提示符处运行 python.exe)时是否会出现相同的问题 。Determine whether the same error occurs using the Python CLI, that is, running python.exe from a command prompt.
- 使用 Visual Studio 安装程序中的“修复”选项 。Use the Repair option in the Visual Studio installer.
- 在 Windows 中通过“设置” > “应用和功能”修复或重新安装 Python 。Repair or reinstall Python through Settings > Apps & features in Windows.
示例错误:未能启动交互式进程:System.ComponentModel.Win32Exception (0x80004005):Microsoft.PythonTools.Repl.PythonInteractiveEvaluator.d__43.MoveNext() 处未知错误 (0xc0000135)。Example error: Failed to start interactive process: System.ComponentModel.Win32Exception (0x80004005): Unknown error (0xc0000135) at Microsoft.PythonTools.Repl.PythonInteractiveEvaluator.d__43.MoveNext().
Visual Studio 2015Visual Studio 2015
- 通过“控制面板”>“程序和功能” ,选择 Microsoft Visual Studio 2015,然后选择“更改” ,从而运行 Visual Studio 安装程序。Run the Visual Studio installer through Control Panel > Programs and Features, selecting Microsoft Visual Studio 2015 and then Change.
- 在安装程序中,选择“修改” 。In the installer, select Modify.
- 选择“编程语言” > “针对 Visual Studio 的 Python 工具” ,然后选择“下一步” :Select Programming Languages > Python Tools for Visual Studio and then Next:
- Visual Studio 安装程序完成后,安装所选的 Python 解释器。Once Visual Studio setup is complete, install a Python interpreter of your choice.Visual Studio 2015 仅支持 Python 3.5 及更早版本;更高版本生成类似“Python 3.6 版本不受支持” 的消息。Visual Studio 2015 supports only Python 3.5 and earlier; later versions generate a message like Unsupported Python version 3.6).如果你已安装解释器且 Visual Studio 不会自动检测它,请参阅手动标识现有环境。If you already have an interpreter installed and Visual Studio doesn't detect it automatically, see Manually identify an existing environment.
Visual Studio 2013 及更早版本Visual Studio 2013 and earlier
- 为你的 Visual Studio 版本安装相应版本的针对 Visual Studio 的 Python 工具:Install the appropriate version of Python Tools for Visual Studio for your version of Visual Studio:
- Visual Studio 2013:PTVS 2.2.2 for Visual Studio 2013。Visual Studio 2013: PTVS 2.2.2 for Visual Studio 2013.Visual Studio 2013 中的“文件” > “新建项目”对话框提供用于此过程的快捷方式 。The File > New Project dialog in Visual Studio 2013 gives you a shortcut for this process.
- Visual Studio 2010 和 2012:PTVS 2.1.1 for Visual Studio 2010 和 2012Visual Studio 2010 and 2012: PTVS 2.1.1 for Visual Studio 2010 and 2012
- 安装所选的 Python 解释器。Install a Python interpreter of your choice.如果你已安装解释器且 Visual Studio 不会自动检测它,请参阅手动标识现有环境。If you already have an interpreter installed and Visual Studio doesn't detect it automatically, see Manually identify an existing environment.
安装位置Install locations
默认情况下,为计算机上的所有用户安装 Python 支持。By default, Python support is installed for all users on a computer.
对于 Visual Studio 2019 和 Visual Studio 2017,Python 工作负载安装在 %ProgramFiles(x86)%Microsoft Visual Studio<VS_version><VS_edition>Common7IDEExtensionsMicrosoftPython 中,其中 <VS_version> 为 2019 或 2017,<VS_edition> 为 Community、Professional 或 Enterprise。For Visual Studio 2019 and Visual Studio 2017, the Python workload is installed in %ProgramFiles(x86)%Microsoft Visual Studio<VS_version><VS_edition>Common7IDEExtensionsMicrosoftPython where <VS_version> is 2019 or 2017 and <VS_edition> is Community, Professional, or Enterprise.
对于 Visual Studio 2015 及更早版本,安装路径如下所示:For Visual Studio 2015 and earlier, installation paths are as follows:
- 32 位:32-bit:
- 路径:%Program Files(x86)%Microsoft Visual Studio <VS_ver>Common7IDEExtensionsMicrosoftPython Tools for Visual Studio<PTVS_ver> Path: %Program Files(x86)%Microsoft Visual Studio <VS_ver>Common7IDEExtensionsMicrosoftPython Tools for Visual Studio<PTVS_ver>
- 路径的注册表位置:HKEY_LOCAL_MACHINESoftwareMicrosoftPythonTools<VS_ver>InstallDirRegistry location of path: HKEY_LOCAL_MACHINESoftwareMicrosoftPythonTools<VS_ver>InstallDir
- 64 位:64-bit:
- 路径:%Program Files%Microsoft Visual Studio <VS_ver>Common7IDEExtensionsMicrosoftPython Tools for Visual Studio<PTVS_ver> Path: %Program Files%Microsoft Visual Studio <VS_ver>Common7IDEExtensionsMicrosoftPython Tools for Visual Studio<PTVS_ver>
- 路径的注册表位置:HKEY_LOCAL_MACHINESoftwareWow6432NodeMicrosoftPythonTools<VS_ver>InstallDirRegistry location of path: HKEY_LOCAL_MACHINESoftwareWow6432NodeMicrosoftPythonTools<VS_ver>InstallDir
其中:where:
- <VS_ver> 是:<VS_ver> is:
- Visual Studio 2015 14.014.0 for Visual Studio 2015
- Visual Studio 2013 12.012.0 for Visual Studio 2013
- Visual Studio 2012 11.011.0 for Visual Studio 2012
- Visual Studio 2010 10.010.0 for Visual Studio 2010
- <PTVS_ver> 是版本号,例如 2.2.2、2.1.1、2.0、1.5、1.1 或 1.0。<PTVS_ver> is a version number, such as 2.2.2, 2.1.1, 2.0, 1.5, 1.1, or 1.0.
特定于用户的安装(1.5 及更早版本)User-specific installations (1.5 and earlier)
仅允许为当前用户安装针对 Visual Studio 的 Python 工具 1.5 版及更早版本,这种情况下的安装路径是 %LocalAppData%MicrosoftVisualStudio<VS_ver>ExtensionsMicrosoftPython Tools for Visual Studio<PTVS_ver>,其中 <VS_ver> 和 <PTVS_ver> 与上文所述相同 。Python Tools for Visual Studio 1.5 and earlier allowed installation for the current user only, in which case the installation path is %LocalAppData%MicrosoftVisualStudio<VS_ver>ExtensionsMicrosoftPython Tools for Visual Studio<PTVS_ver> where <VS_ver> and <PTVS_ver> are the same as described above.
-->Visual Studio for Mac is a .NET integrated development environment on the Mac that can be used to edit, debug, and build code and then publish an app. In addition to expected features, such as a standard editor and debugger, Visual Studio for Mac includes compilers, code completion tools, graphical designers, and source control to ease the software development process.
Visual Studio for Mac supports many of the same file types as its Windows counterpart, such as
.csproj
, .fsproj
, or .sln
files, and supports features such as EditorConfig, meaning that you can use the IDE that works best for you.Creating, opening, and developing an app will be a familiar experience for anyone who has previously used Visual Studio on Windows. In addition, Visual Studio for Mac employs many of the powerful tools that make its Windows counterpart such a powerful IDE. The Roslyn Compiler Platform is used for refactoring and IntelliSense. Its project system and build engine use MSBuild, and its source editor uses the same foundation as Visual Studio on Windows. It uses the same debugger engines for Xamarin and .NET Core apps, and the same designers for Xamarin.iOS and Xamarin.Android.What can I do in Visual Studio for Mac
Visual Studio for Mac supports the following types of development:
- ASP.NET Core web applications with C#, F#, and support for Razor pages, JavaScript, and TypeScript
- .NET Core console applications with C# or F#
- Cross-platform Unity games and applications with C#
- Android, iOS, tvOS, and watchOS applications in Xamarin with C# or F# and XAML
- Cocoa desktop apps in C# or F#
This article explores various sections of Visual Studio for Mac, providing a look at some of the features that make it a powerful tool for creating these applications.
IDE tour
Visual Studio for Mac is organized into several sections for managing application files and settings, creating application code, and debugging.
Getting started
When you start Visual Studio 2019 for Mac, new users will see a sign-in window. Sign-in with your Microsoft account to activate a paid license (if you have one) or link to Azure subscriptions. You can press I'll do this later and sign in later via the Visual Studio > Sign in menu item:
Microsoft Visual Studio 2012 For Mac
You'll then be given the option to customize the IDE by selecting your preferred keyboard shortcuts: Visual Studio for Mac, Visual Studio, Visual Studio Code, or Xcode:
Signed-in users will see the new start window, which shows a list of recent projects, and buttons to open an existing project or create a new one:
Solutions and projects
![Microsoft Visual Studio 2012 Mac Microsoft Visual Studio 2012 Mac](https://i.gadgets360cdn.com/large/visual_studio_2017_mac_1494826363897.png)
The following image shows Visual Studio for Mac with an application loaded:
The following sections provide an overview of the major areas in Visual Studio for Mac.
Solution pad
The Solution Pad organizes the project(s) in a solution:
This is where files for the source code, resources, user interface, and dependencies are organized into platform-specific Projects.
For more information on using Projects and Solutions in Visual Studio for Mac, see the Projects and Solutions article.
Assembly references
Assembly references for each project are available under the References folder:
Additional references are added using the Edit References dialog, which is displayed by double-clicking on the References folder, or by selecting Edit References on its context menu actions:
For more information on using References in Visual Studio for Mac, see the Managing References in a Project article.
Dependencies / packages
All external dependencies used in your app are stored in the Dependencies or Packages folder, depending on whether you are in a .Net Core or Xamarin.iOS/Xamarin.Android project. These are usually provided in the form of a NuGet.
NuGet is the most popular package manager for .NET development. With Visual Studio's NuGet support, you can easily search for and add packages to your project to application.
To add a dependency to your application, right-click on the Dependencies / Packages folder, and select Add Packages:
Information on using a NuGet package in an application can be found in the Including a NuGet project in your project article.
Source Editor
Regardless of if you're writing in C#, XAML, or Javascript, the code editor the shares the same core components with Visual Studio Windows, with an entirely native user interface.
This brings some of the following features:
- Native macOS (Cocoa-based) user interface (tooltips, editor surface, margin adornments, text rendering, IntelliSense)
- IntelliSense type filtering and 'show import items'
- Support for native text inputs
- RTL/BiDi language support
- Roslyn 3
- Multi-caret support
- Word wrap
- Updated IntelliSense UI
- Improved find/replace
- Snippet support
- Format selection
- Inline lightbulbs
For more information on using the Source Editor in Visual Studio for Mac, see the Source Editor documentation.
To keep tabs visible at all times, you can take advantage of pinning them. This ensures that every time you launch a project, the tab you need will always appear. To pin a tab, hover over the tab and click the pin icon:
Visual Studio 2012 Download
Refactoring
Visual Studio for Mac provides two useful ways to refactor your code: Context Actions, and Source Analysis. You can read more about them in the Refactoring article.
Debugging
Visual Studio for Mac has debuggers that support .NET Core, .NET Framework, Unity, and Xamarin projects. Visual Studio for Mac uses the .NET Core debugger and the Mono Soft Debugger, allowing the IDE to debug managed code across all platforms. For additional information on debugging, visit the Debugging article.
The debugger contains rich visualizers for special types such as strings, colors, URLs, as well as sizes, coordinates, and bézier curves.
For more information on the debugger's data visualizations, visit the Data Visualizations article.
Version control
Visual Studio for Mac integrates with Git and Subversion source control systems. Projects under source control are denoted with the branch listed next to the Solution name:
Files with uncommitted changes have an annotation on their icons in the Solution Pane, as illustrated in the following image:
For more information on using version control in Visual Studio, see the Version Control article.