azure/kudu将python路径从2.7更新到3.6

hvvq6cgz  于 2021-06-24  发布在  Kudu
关注(0)|答案(1)|浏览(368)

我试了一整天从visualstudio发布我的django项目,我想我已经解决了这个问题。当它自动创建环境时,它安装了python2.7。我使用的是django 2.2+,它只在python3+上运行。
python 3.6路径:

D:\home\python364x64>

我可以让环境在会话中使用3.6,但我无法从kudu powershell或azure门户解决如何使更改永久化的问题。
很明显,我遗漏了一些非常简单的东西,但是没有一个文档包含这个问题。
这也是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>

应用程序主机.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变量。
除此之外,我已经让初始登录页和连续交付工作得很好(通过在默认登录页上更改文本、在浏览器中保存和刷新来测试)
此外,这是在Kudu的路径下显示的内容:

D:\home\site\deployments\tools
D:\Program Files (x86)\SiteExtensions\Kudu\82.10503.3890\bin\Scripts
D:\Program Files (x86)\MSBuild\14.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 Server\110\Tools\Binn
D:\Program Files (x86)\Microsoft SDKs\F#\3.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\3.10.8
C:\DWASFiles\Sites\#1FTAData\AppData\npm
D:\Program Files (x86)\bower\1.7.9
D:\Program Files (x86)\grunt\0.1.13
D:\Program Files (x86)\gulp\3.9.0.1
D:\Program Files (x86)\funcpack\1.0.0
D:\Program Files (x86)\nodejs\6.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
wmvff8tz

wmvff8tz1#

首先,你需要安装python的版本,你可以去扩展或安装包。
转到azure应用程序下的扩展,选择添加扩展并选择所需版本。因为你已经有了会话路径,我想你已经安装了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>

欲知详情,请向官方咨询doc:set up azure应用程序上的python环境。
更新:如果web.config方法不起作用,您可以转到azure app->path mappings->+new handler下的配置
分机: fastCgi 处理器: D:\home\python364x64\python.exe 论据: D:\home\python364x64\wfastcgi.py 保存设置。

重新启动应用程序并转到应用程序kudu,检查设置是否有效。

相关问题