vs可以开发python吗_Visual Studio 中的 Python 教程步骤 1,创建项目 | Microsoft Docs

教程:在 Visual Studio 中使用 PythonTutorial: Work with Python in Visual Studio

01/28/2019

JoshuaPartlow.png?size=32

olprod.png?size=32

本文内容

Python 是一种受欢迎的编程语言,它可靠、灵活、易于学习、可在所有操作系统上免费使用,并且强大的开发人员社区和很多免费库都支持它。Python is a popular programming language that is reliable, flexible, easy to learn, free to use on all operating systems, and supported by both a strong developer community and many free libraries. 该语言支持所有开发方式,包括 Web 应用程序、Web 服务、桌面应用、脚本编写和科学计算,许多高校人员、科学家、业余和专业开发人员都在使用 Python。The language supports all manners of development, including web applications, web services, desktop apps, scripting, and scientific computing and is used by many universities, scientists, casual developers, and professional developers alike.

Visual Studio 为 Python 提供一级语言支持。Visual Studio provides first-class language support for Python. 本教程将指导你完成以下步骤:This tutorial guides you through the following steps:

系统必备Prerequisites

安装有 Python 工作负载的 Visual Studio 2017。Visual Studio 2017 with the Python workload installed.

安装有 Python 工作负载的 Visual Studio 2019。Visual Studio 2019 with the Python workload installed.

还可以使用安装有针对 Visual Studio 的 Python 工具的 Visual Studio 早期版本。You can also use an earlier version of Visual Studio with the Python Tools for Visual Studio installed.

步骤 1:创建新的 Python 项目Step 1: Create a new Python project

项目是 Visual Studio 管理所有文件(包括源代码、资源、配置等等)的一种方式,这些文件结合在一起可生成单个应用程序。A project is how Visual Studio manages all the files that come together to produce a single application, including source code, resources, configurations, and so on. 项目可规范和维护其所有文件以及由多个项目共享的外部资源之间的关系。A project formalizes and maintains the relationship between all the project's files as well as external resources that are shared between multiple projects. 比起在临时文件夹、脚本、文本文件中甚至完全按自己的想法简单地管理项目关系,这样做让应用程序能够更轻松地扩展和增长。As such, projects allow your application to effortlessly expand and grow much easier than simply managing a project's relationships in ad hoc folders, scripts, text files, and even your own mind.

本教程将从一个包含单一空代码文件的简单项目开始。In this tutorial you begin with a simple project containing a single, empty code file.

在 Visual Studio 中,选择“文件” > “新建” > “项目”(Ctrl+Shift+N),这会打开“新建项目”对话框。In Visual Studio, select File > New > Project (Ctrl+Shift+N), which brings up the New Project dialog. 可在该对话框中浏览各种语言的模板,然后为项目选择一个模板,并指定 Visual Studio 放置文件的位置。Here you browse templates across different languages, then select one for your project and specify where Visual Studio places files.

若要查看 Python 模板,可在左侧选择“已安装” > “Python”或搜索“Python”。To view Python templates, select Installed > Python on the left, or search for "Python". 如果忘记了模板在语言树中的位置,使用搜索是找到该模板的好方法。Using search is a great way to find a template when you can't remember its location in the languages tree.

vs-getting-started-python-01-new-project.png?view=vs-2019

注意 Visual Studio 中的 Python 支持如何包含大量项目模板,包括使用 Bottle、Flask 和 Django 框架的 Web 应用程序。Notice how Python support in Visual Studio includes a number of project templates, including web applications using the Bottle, Flask, and Django frameworks. 但为了便于演示,我们以空项目开始。For the purposes of this walkthrough, however, let's start with an empty project.

选择“Python 应用程序”模板,为项目指定名称并选择“确定”。Select the Python Application template, specify a name for the project, and select OK.

几分钟后,Visual Studio 会在“解决方案资源管理器”窗口 (1) 中显示项目结构。After a few moments, Visual Studio shows the project structure in the Solution Explorer window (1). 默认代码文件在编辑器 (2) 中处于打开状态。The default code file is open in the editor (2). “属性”窗口 (3) 也会出现,其中显示在“解决方案资源管理器”中选定的任何项的附加信息(包括它在磁盘上的确切位置)。The Properties window (3) also appears to show additional information for any item selected in Solution Explorer, including its exact location on disk.

vs-getting-started-python-02-windows.png?view=vs-2019

花点时间熟悉一下“解决方案资源管理器”,可在该管理器中浏览项目中的文件和文件夹。Take a few moments to familiarize yourself with Solution Explorer, which is where you browse files and folders in your project.

vs-getting-started-python-03-solution-explorer.png?view=vs-2019

(1) 粗体突出显示的是项目,其名称是在“新建项目”对话框中指定的名称。(1) Highlighted in bold is your project, using the name you gave in the New Project dialog. 在磁盘上,此项目由项目文件夹中的 .pyproj 文件表示。On disk, this project is represented by a .pyproj file in your project folder.

(2) 顶层是一个解决方案,它与项目默认同名。(2) At the top level is a solution, which by default has the same name as your project. 解决方案在磁盘上由 .sln 文件表示,是一个或多个相关项目的容器。A solution, represented by a .sln file on disk, is a container for one or more related projects. 例如,如果为 Python 应用程序编写 C++ 扩展,该 C++ 项目可以驻留在同一解决方案中。For example, if you write a C++ extension for your Python application, that C++ project could reside within the same solution. 解决方案还可以包含 Web 服务的项目,以及专用测试程序的项目。The solution might also contain a project for a web service, along with projects for dedicated test programs.

(3) 在项目下方可以看到源文件,在本例中,只有一个 .py 文件。(3) Under your project you see source files, in this case only a single .py file. 选择文件时会在“属性”窗口中显示其属性。Selecting a file displays its properties in the Properties window. 双击文件会以任何适合该文件的方式打开该文件。Double-clicking a file opens it in whatever way is appropriate for that file.

(4) 项目下方还有“Python 环境”节点。(4) Also under the project is the Python Environments node. 展开后,可以看到可用的 Python 解释器。When expanded, you see the Python interpreters that are available to you. 展开解释器节点可查看安装到该环境 (5) 中的库。Expand an interpreter node to see the libraries that are installed into that environment (5).

右键单击“解决方案资源管理器”中的任意节点或项均可访问适用命令菜单。Right-click any node or item in Solution Explorer to access a menu of applicable commands. 例如,“重命名”命令可用于更改任何节点或项(包括项目和解决方案)的名称。For example, the Rename command allows you to change the name of any node or item, including the project and the solution.

下一步Next step

深入了解Go deeper

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值