Azure/Kudu 将 python 路径从 2.7 更新到 3.6
Azure/Kudu update python PATH from 2.7 to 3.6
我一整天都在尝试从 Visual Studio 发布我的 Django 项目,我想我已经解决了这个问题。当它自动创建环境时,它安装了 Python 2.7。我正在使用 Django 2.2+,它只能在 Python 3+ 上运行。
Python 3.6路径:
D:\home\python364x64>
我可以让环境在会话中使用 3.6,但我不知道如何从 Kudu Powershell 或 Azure 门户中使更改永久生效。
我显然遗漏了一些非常简单的东西,但是 none 的文档涵盖了这个问题。
这也是 web.config 文件。我不知道它是否有帮助,所以我会添加它,因为信息太多总比信息不够好:
<configuration>
<system.webServer>
<handlers>
<add name="PythonHandler" path="handler.fcgi" verb="*" modules="FastCgiModule" scriptProcessor="D:\home\python364x64\Scripts\pip3.exe" resourceType="Unspecified" requireAccess="Script"/>
</handlers>
<rewrite>
<rules>
<rule name="Static Files" stopProcessing="true">
<conditions>
<add input="true" pattern="false" />
</conditions>
</rule>
<rule name="Configure Python" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<conditions>
<add input="{REQUEST_URI}" pattern="^/static/.*" ignoreCase="true" negate="true" />
</conditions>
<action type="Rewrite" url="handler.fcgi/{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
<system.webServer>
<handlers>
<add name="PythonHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified"/>
</handlers>
<httpPlatform processPath="D:\home\python364x64\Scripts\pip3.exe"
arguments="D:\home\site\wwwroot\runserver.py --port %HTTP_PLATFORM_PORT%"
stdoutLogEnabled="true"
stdoutLogFile="D:\home\LogFiles\python.log"
startupTimeLimit="60"
processesPerApplication="16">
<environmentVariables>
<environmentVariable name="SERVER_PORT" value="%HTTP_PLATFORM_PORT%" />
</environmentVariables>
</httpPlatform>
</system.webServer>
<appSettings>
<add key="WSGI_HANDLER" value="django.core.wsgi.get_wsgi_application()"/>
<add key="PYTHONPATH" value="D:\homepython364x64\Scripts"/>
<add key="WSGI_LOG" value="D:\home\LogFiles\wfastcgi.log"/>
<add key="DJANGO_SETTINGS_MODULE" value="FTAData.settings" />
</appSettings>
<system.webServer>
<handlers>
<add name="PythonHandler" path="*" verb="*" modules="FastCgiModule"
scriptProcessor="D:\home\python364x64\Scripts\pip3.exe"
resourceType="Unspecified" requireAccess="Script"/>
</handlers>
</system.webServer>
</configuration>
applicationHost.xtd:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer>
<runtime xdt:Transform="InsertIfMissing">
<environmentVariables xdt:Transform="InsertIfMissing">
<add name="PATH" value="D:\home\python364x64\Scripts" xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />
</environmentVariables>
</runtime>
</system.webServer>
</configuration>
编辑:
我忘了说,我在 Python3.6 文件夹中有 运行 我的需求文件,它完美地完成了。我得到的唯一错误消息是 PATH 变量。
最重要的是,我的初始登陆页面和持续交付也运行良好(通过更改默认登陆页面上的文本、在浏览器中保存和刷新进行测试)
此外,这是在 PATH 下的 Kudu 中显示的内容:
D:\home\site\deployments\tools
D:\Program Files (x86)\SiteExtensions\Kudu.10503.3890\bin\Scripts
D:\Program Files (x86)\MSBuild.0\Bin
D:\Program Files\Git\cmd
D:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow
D:\Program Files (x86)\Microsoft SQL Server0\Tools\Binn
D:\Program Files (x86)\Microsoft SDKs\F#.1\Framework\v4.0
D:\Program Files\Git\bin
D:\Program Files\Git\usr\bin
D:\Program Files\Git\mingw64\bin
D:\Program Files (x86)\npm.10.8
C:\DWASFiles\Sites\#1FTAData\AppData\npm
D:\Program Files (x86)\bower.7.9
D:\Program Files (x86)\grunt[=15=].1.13
D:\Program Files (x86)\gulp.9.0.1
D:\Program Files (x86)\funcpack.0.0
D:\Program Files (x86)\nodejs.9.1
D:\Windows\system32
D:\Windows
D:\Windows\System32\Wbem
D:\Windows\System32\WindowsPowerShell\v1.0\
D:\Users\Administrator\AppData\Local\Microsoft\WindowsApps
D:\Program Files (x86)\dotnet
D:\Windows\system32\config\systemprofile\AppData\Local\Microsoft\WindowsApps
D:\Program Files (x86)\Git\cmd
D:\Program Files (x86)\PHP\v5.6
D:\Python27
首先,你需要安装python版本,你可以去扩展或安装包。
在 azure app 下转到您的扩展程序,选择添加扩展程序并选择您想要的版本。因为你已经有了会话路径,我想你已经安装了python。你可以直接去设置web.config.
你可以设置HttpPlatform(推荐)或FastCGI,下面是一个HttpPlatform示例。
<configuration>
<system.webServer>
<handlers>
<add name="PythonHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified"/>
</handlers>
<httpPlatform processPath="D:\home\Python361x64\python.exe"
arguments="D:\home\site\wwwroot\runserver.py --port %HTTP_PLATFORM_PORT%"
stdoutLogEnabled="true"
stdoutLogFile="D:\home\LogFiles\python.log"
startupTimeLimit="60"
processesPerApplication="16">
<environmentVariables>
<environmentVariable name="SERVER_PORT" value="%HTTP_PLATFORM_PORT%" />
</environmentVariables>
</httpPlatform>
</system.webServer>
</configuration>
更多细节可以参考官方文档:set up a Python environment on Azure App.
更新:如果web.config方法不行,你可以去Azure App下的Configuration-> Path mappings->+ New handler
分机:fastCgi
处理器:D:\home\python364x64\python.exe
参数:D:\home\python364x64\wfastcgi.py
保存您的设置。
重新启动您的应用程序并转到您的应用程序 kudu,检查设置是否有效。
我一整天都在尝试从 Visual Studio 发布我的 Django 项目,我想我已经解决了这个问题。当它自动创建环境时,它安装了 Python 2.7。我正在使用 Django 2.2+,它只能在 Python 3+ 上运行。
Python 3.6路径:
D:\home\python364x64>
我可以让环境在会话中使用 3.6,但我不知道如何从 Kudu Powershell 或 Azure 门户中使更改永久生效。
我显然遗漏了一些非常简单的东西,但是 none 的文档涵盖了这个问题。
这也是 web.config 文件。我不知道它是否有帮助,所以我会添加它,因为信息太多总比信息不够好:
<configuration>
<system.webServer>
<handlers>
<add name="PythonHandler" path="handler.fcgi" verb="*" modules="FastCgiModule" scriptProcessor="D:\home\python364x64\Scripts\pip3.exe" resourceType="Unspecified" requireAccess="Script"/>
</handlers>
<rewrite>
<rules>
<rule name="Static Files" stopProcessing="true">
<conditions>
<add input="true" pattern="false" />
</conditions>
</rule>
<rule name="Configure Python" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<conditions>
<add input="{REQUEST_URI}" pattern="^/static/.*" ignoreCase="true" negate="true" />
</conditions>
<action type="Rewrite" url="handler.fcgi/{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
<system.webServer>
<handlers>
<add name="PythonHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified"/>
</handlers>
<httpPlatform processPath="D:\home\python364x64\Scripts\pip3.exe"
arguments="D:\home\site\wwwroot\runserver.py --port %HTTP_PLATFORM_PORT%"
stdoutLogEnabled="true"
stdoutLogFile="D:\home\LogFiles\python.log"
startupTimeLimit="60"
processesPerApplication="16">
<environmentVariables>
<environmentVariable name="SERVER_PORT" value="%HTTP_PLATFORM_PORT%" />
</environmentVariables>
</httpPlatform>
</system.webServer>
<appSettings>
<add key="WSGI_HANDLER" value="django.core.wsgi.get_wsgi_application()"/>
<add key="PYTHONPATH" value="D:\homepython364x64\Scripts"/>
<add key="WSGI_LOG" value="D:\home\LogFiles\wfastcgi.log"/>
<add key="DJANGO_SETTINGS_MODULE" value="FTAData.settings" />
</appSettings>
<system.webServer>
<handlers>
<add name="PythonHandler" path="*" verb="*" modules="FastCgiModule"
scriptProcessor="D:\home\python364x64\Scripts\pip3.exe"
resourceType="Unspecified" requireAccess="Script"/>
</handlers>
</system.webServer>
</configuration>
applicationHost.xtd:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer>
<runtime xdt:Transform="InsertIfMissing">
<environmentVariables xdt:Transform="InsertIfMissing">
<add name="PATH" value="D:\home\python364x64\Scripts" xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />
</environmentVariables>
</runtime>
</system.webServer>
</configuration>
编辑: 我忘了说,我在 Python3.6 文件夹中有 运行 我的需求文件,它完美地完成了。我得到的唯一错误消息是 PATH 变量。
最重要的是,我的初始登陆页面和持续交付也运行良好(通过更改默认登陆页面上的文本、在浏览器中保存和刷新进行测试)
此外,这是在 PATH 下的 Kudu 中显示的内容:
D:\home\site\deployments\tools
D:\Program Files (x86)\SiteExtensions\Kudu.10503.3890\bin\Scripts
D:\Program Files (x86)\MSBuild.0\Bin
D:\Program Files\Git\cmd
D:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow
D:\Program Files (x86)\Microsoft SQL Server0\Tools\Binn
D:\Program Files (x86)\Microsoft SDKs\F#.1\Framework\v4.0
D:\Program Files\Git\bin
D:\Program Files\Git\usr\bin
D:\Program Files\Git\mingw64\bin
D:\Program Files (x86)\npm.10.8
C:\DWASFiles\Sites\#1FTAData\AppData\npm
D:\Program Files (x86)\bower.7.9
D:\Program Files (x86)\grunt[=15=].1.13
D:\Program Files (x86)\gulp.9.0.1
D:\Program Files (x86)\funcpack.0.0
D:\Program Files (x86)\nodejs.9.1
D:\Windows\system32
D:\Windows
D:\Windows\System32\Wbem
D:\Windows\System32\WindowsPowerShell\v1.0\
D:\Users\Administrator\AppData\Local\Microsoft\WindowsApps
D:\Program Files (x86)\dotnet
D:\Windows\system32\config\systemprofile\AppData\Local\Microsoft\WindowsApps
D:\Program Files (x86)\Git\cmd
D:\Program Files (x86)\PHP\v5.6
D:\Python27
首先,你需要安装python版本,你可以去扩展或安装包。
在 azure app 下转到您的扩展程序,选择添加扩展程序并选择您想要的版本。因为你已经有了会话路径,我想你已经安装了python。你可以直接去设置web.config.
你可以设置HttpPlatform(推荐)或FastCGI,下面是一个HttpPlatform示例。
<configuration>
<system.webServer>
<handlers>
<add name="PythonHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified"/>
</handlers>
<httpPlatform processPath="D:\home\Python361x64\python.exe"
arguments="D:\home\site\wwwroot\runserver.py --port %HTTP_PLATFORM_PORT%"
stdoutLogEnabled="true"
stdoutLogFile="D:\home\LogFiles\python.log"
startupTimeLimit="60"
processesPerApplication="16">
<environmentVariables>
<environmentVariable name="SERVER_PORT" value="%HTTP_PLATFORM_PORT%" />
</environmentVariables>
</httpPlatform>
</system.webServer>
</configuration>
更多细节可以参考官方文档:set up a Python environment on Azure App.
更新:如果web.config方法不行,你可以去Azure App下的Configuration-> Path mappings->+ New handler
分机:fastCgi
处理器:D:\home\python364x64\python.exe
参数:D:\home\python364x64\wfastcgi.py
保存您的设置。
重新启动您的应用程序并转到您的应用程序 kudu,检查设置是否有效。