简体   繁体   English

在Microsoft Azure WebJob中指定Python版本?

[英]Specify Python version in Microsoft Azure WebJob?

How can I select which Python version to use for a WebJob on Microsoft Azure? 如何在Microsoft Azure上选择用于WebJob的Python版本?

When I do print(sys.version) I get 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)] 当我执行print(sys.version)我得到2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)]

Where can I specify another version? 在哪里可以指定其他版本? I would like to use Python 3 for some jobs. 我想将Python 3用于某些工作。 I have tried adding runtime.txt reading python-3.4 to the root path, but it had no effect. 我曾尝试将运行读取python-3.4 runtime.txt添加到根路径,但是没有任何效果。

Also if you wanna run different python versions in the same site, you can always drop a run.cmd that calls the right version of python for you. 另外,如果您想在同一站点中运行不同的python版本,则始终可以删除一个run.cmd来为您调用正确的python版本。 They are installed in D:\\Python34 and D:\\Python27 它们安装在D:\\Python34D:\\Python27

Azure WebJobs run in the context of your App Service plan. Azure WebJob在您的App Service计划的上下文中运行。

By default, the python version is 2.7 (as you've discovered). 默认情况下,python版本是2.7(如您所见)。 To change this, you'll need to look at the settings for your App Service plan and change the python version. 要更改此设置,您需要查看App Service计划的设置并更改python版本。

Here's an example, from one of my App Service plans. 这是一个示例,来自我的一项App Service计划。 Initially, it was unset, but I changed it to 3.4: 最初,它未设置,但我将其更改为3.4:

python版本设置

I also created a test webjob in python: 我还在python中创建了一个测试webjob:

import sys
print (sys.version)

I ran it before changing the python settings: 我在更改python设置之前运行了它:

python 2.7输出

I then changed the python version to 3.4 in the App Service settings, and ran it again: 然后,我在App Service设置中将python版本更改为3.4,然后再次运行它:

python 3.4输出

Beside David Makogon's answer, we also can configure the python version in current Azure manage portal . 除了David Makogon的答案,我们还可以在当前的Azure管理门户中配置python版本。

In the manage portal of your Azure Web Apps, in configure tab, under general section, we can specify the python version which will be configured in your Web App runtime. 在Azure Web Apps的管理门户的“常规”部分的“配置”选项卡中,我们可以指定将在Web App运行时中配置的python版本。 Restart your site after your saving your configuration. 保存配置后,重新启动站点。 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM