安装 Python 和 SDKInstalling Python and the SDK

在 Windows 上安装 Python 很简单,并且 Mac、Linux 和 Bash for Windows上可能已预安装了 Python。Python is easy to setup on Windows and comes pre-installed on Mac, Linux, and Bash for Windows. 本指南指导完成安装过程,并使计算机可随时用于 Azure。This guide walks you through installation and getting your machine ready for use with Azure.

Python Azure SDK 包含哪些内容?What's in the Python Azure SDK?

Azure SDK for Python 包括允许针对 Azure 开发、部署和管理 Python 应用程序的组件。The Azure SDK for Python includes components that allow you to develop, deploy, and manage Python applications for Azure. 具体而言,Azure SDK for Python 包括以下组件:Specifically, the Azure SDK for Python includes the following:

  • 管理库Management libraries. 这些类库提供管理 Azure 资源(例如存储帐户、虚拟机)的接口。These class libraries provide an interface managing Azure resources, such as storage accounts, virtual machines.

  • 运行时库Runtime libraries. 这些类库提供用于访问 Azure 功能(例如存储和服务总线)的接口。These class libraries provide an interface for accessing Azure features, such as storage and service bus.

要使用哪种 Python 以及哪个版本Which Python and which version to use

提供了多种形式的 Python 解释程序 - 示例包括:There are several flavors of Python interpreters available - examples include:

  • CPython - 最常用的标准 Python 解释程序CPython - the standard and most commonly used Python interpreter
  • PyPy - 快速、CPython 的合规替代实现PyPy - fast, compliant alternative implementation to CPython
  • IronPython - 在 .Net/CLR 上运行的 Python 解释程序IronPython - Python interpreter that runs on .Net/CLR
  • Jython - 在 Java 虚拟机上运行的 Python 解释程序Jython - Python interpreter that runs on the Java Virtual Machine

CPython v2.7 或 v3.3+ 和 PyPy 5.4.0 已经过 Python Azure SDK 测试,且受其支持。CPython v2.7 or v3.3+ and PyPy 5.4.0 are tested and supported for the Python Azure SDK.

从哪里获得 Python?Where to get Python?

有多种方法可获得 CPython:There are several ways to get CPython:

除非有特定需求,否则建议使用前两个选项。Unless you have a specific need, we recommend the first two options.

Windows、Linux 和 MacOS 上的 SDK 安装(仅限客户端库)SDK Installation on Windows, Linux, and MacOS (client libraries only)

如果已安装 Python,则可以使用 pip 在现有的 Python 2.7 或 Python 3.3+ 环境中安装所有客户端库的捆绑包。If you already have Python installed, you can use pip to install a bundle of all the client libraries in your existing Python 2.7 or Python 3.3+ environment. 这将从 Python 包索引 (PyPI) 中下载包。This will download the packages from the Python Package Index (PyPI).

可能需要管理员权限:You may need administrator rights:

  • 对于 Linux 和 MacOS,使用 sudo 命令:sudo pip install azure-mgmt-computeLinux and MacOS, use the sudo command: sudo pip install azure-mgmt-compute.
  • Windows:以管理员身份打开 PowerShell 提示符或命令提示符Windows: open your PowerShell/Command prompt as an administrator

可以为每个 Azure 服务分别安装每个库:You can install individually each library for each Azure service:

   $ pip install azure-batch          # Install the latest Batch runtime library
   $ pip install azure-mgmt-scheduler # Install the latest Storage management library

可以使用 --pre 标志安装预览包:Preview packages can be installed using the --pre flag:

   $ pip install --pre azure-mgmt-compute # will install only the latest Compute Management library

还可以使用 azure 元程序包在单个行中安装一组 Azure 库。You can also install a set of Azure libraries in a single line using the azure meta-package. 由于此元程序包中并非所有包都已作为稳定版本发布,因此 azure 元程序包仍为预览版。Since not all packages in this meta-package are published as stable yet, the azure meta-package is still in preview. 但是这一次,核心程序包的代码质量/完整性方面都可以被视为是“稳定”的However, the core packages, from code quality/completeness perspectives can be considered "stable" at this time

  • 我们会尽快将其正式标记为“稳定”(与其他语言同步)。it will be officially labeled as such in sync with other languages as soon as possible. 在那之前,我们不会作出任何重大的更改。We are not planning on any further major changes until then.

由于这是预览版本,需要使用 --pre 标志:Since it's a preview release, you need to use the --pre flag:

   $ pip install --pre azure

或直接or directly

   $ pip install azure==2.0.0rc6

获取多个软件包Getting More Packages

Python 包索引 (PyPI) 提供丰富的 Python 库。The Python Package Index (PyPI) has a rich selection of Python libraries. 如果选择安装发行版本,表明你重点关注的是从 Web 开发到技术计算的各种方案。If you chose to install a Distro, you'll already have most of the interesting bits for various scenarios from web development to Technical Computing.

Python Tools for Visual StudioPython Tools for Visual Studio

Python Tools for Visual Studio (PTVS) 是 Microsoft 提供的免费/OSS 插件,可将 VS 转换为完备的 Python IDE:Python Tools for Visual Studio (PTVS) is a free/OSS plugin from Microsoft, which turns VS into a full-fledged Python IDE:

how-to-install-python-ptvs

可以选择是否使用 PTVS,但建议使用,因为它能够提供 Python 和 Web 项目/解决方案支持、调试、分析、交互式窗口、模板编辑和智能感知。Using PTVS is optional, but is recommended as it gives you Python and Web Project/Solution support, debugging, profiling, interactive window, Template editing, and Intellisense.

PTVS 还可以轻松实现部署到 Microsoft Azure,同时支持部署到云服务网站PTVS also makes it easy to deploy to Microsoft Azure, with support for deployment to Cloud Services and Websites.

PTVS 适用于现有的 Visual Studio 2013 或 2015 版本的安装。PTVS works with your existing Visual Studio 2013 or 2015 installation. 有关文档、下载和讨论的信息,请参阅 Python Tools for Visual StudioFor documentation, downloads and discussions, see Python Tools for Visual Studio.

Python Azure 方案适用于 Linux 和 MacOSPython Azure Scenarios for Linux and MacOS

对于 Linux 或 MacOS,支持的主要 Azure 方案为:For Linux or MacOS, main Azure scenarios that are supported:

  1. 通过使用 Python 的客户端库来使用 Azure 服务Consuming Azure Services by using the client libraries for Python

  2. 在 Linux VM 中运行应用程序Running your app in a Linux VM

  3. 使用 Git 开发和发布到 Azure 网站Developing and publishing to Azure Websites using Git

使用第一个方案可以通过 Azure REST API 的 Pythonic 包装来创作利用 Azure PaaS 功能(例如 Blob 存储队列存储表存储等)的丰富 Web 应用。The first scenario enables you to author rich web apps that take advantage of the Azure PaaS capabilities such as blob storage, queue storage, table storage etc. via Pythonic wrappers for the Azure REST APIs. 这些应用程序在 Windows、Mac 和 Linux 上的工作方式是相同的。These works identically on Windows, Mac, and Linux. 此外可以从本地开发计算机或在 Azure 上运行的 Linux VM 中使用这些客户端库。You can also use these client libraries from your local development machine or a Linux VM running on Azure.

对于 VM 方案,只需启动所选的 Linux VM(Ubuntu、CentOS、Suse)并运行/管理所需内容。For the VM scenario, you simply start a Linux VM of your choice (Ubuntu, CentOS, Suse) and run/manage what you like. 例如,可以在 Windows/Mac/Linux 计算机上运行 IPython REPL/notebook,并使浏览器指向在 Azure 上运行 IPython 引擎的 Linux 或 Windows 多处理器 VM。As an example, you can run IPython REPL/notebook on your Windows/Mac/Linux machine and point your browser to a Linux or Windows multi-proc VM running the IPython Engine on Azure. 请参阅 Azure 上的 IPython Notebook 教程,以了解详细信息。See the IPython Notebook on Azure tutorial for more information.

有关如何安装 Linux VM 的信息,请参阅 创建运行 Linux 的虚拟机 教程。For information on how to setup a Linux VM, please see the Create a Virtual Machine Running Linux tutorial.

使用 Git 部署,可以从任何操作系统开发 Python web 应用程序并将其发布到 Azure 网站。Using Git deployment, you can develop a Python web application and publish it to an Azure Website from any operating system. 当将存储库推送到 Azure 时,它会自动创建虚拟环境和 pip 安装所需的包。When you push your repository to Azure, it will automatically create a virtual environment and pip install your required packages.

有关开发和发布 Azure 网站的详细信息,请参阅有关教程:使用 Django 创建网站(使用 Django 创建网站)、使用 Bottle 创建网站(使用 Bottle 创建网站)和 使用 Flask 创建网站(使用 Flask 创建网站)。For more information on developing and publishing Azure Websites, see the tutorials for Creating Websites with Django, Creating Websites with Bottle, and Creating Websites with Flask. 有关使用任何 WSGI 合规框架的更多常规信息,请参阅 配置 Azure 网站的 PythonFor more general information on using any WSGI-compliant framework, see Configuring Python with Azure Websites.

其他软件和资源:Additional Software and Resources: