如何在 azure python 应用服务中将目录添加到 PATH

Posted

技术标签:

【中文标题】如何在 azure python 应用服务中将目录添加到 PATH【英文标题】:How to add directory to PATH in azure python app service 【发布时间】:2020-09-15 09:11:51 【问题描述】:

我的python azure app 运行良好。我已经在其中安装了cmake

python -m pip install cmake

这安装得很好,但我也收到了以下警告:

WARNING: The scripts cmake.exe, cpack.exe and ctest.exe are installed in 'D:\home\python364x64\Scripts'
which is not on PATH. Consider adding this directory to PATH

由于上述警告,如果我正在安装任何其他需要安装 cmake 的软件包,我会收到 cmake 未找到的错误。

我输入了PATH,它显示了所有值的列表。如何在PATH 中添加目录D:\home\python364x64\Scripts。请帮忙。谢谢

【问题讨论】:

【参考方案1】:

有官方教程:How to set up a Python environment on Azure App Service。

配置 HttpPlatform 处理程序

<?xml version="1.0" encoding="utf-8"?>
<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>

配置 FastCGI 处理程序

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="PYTHONPATH" value="D:\home\site\wwwroot"/>
    <!-- The handler here is specific to Bottle; other frameworks vary. -->
    <add key="WSGI_HANDLER" value="app.wsgi_app()"/>
    <add key="WSGI_LOG" value="D:\home\LogFiles\wfastcgi.log"/>
  </appSettings>
  <system.webServer>
    <handlers>
      <add name="PythonHandler" path="*" verb="*" modules="FastCgiModule"
           scriptProcessor="D:\home\Python361x64\python.exe|D:\home\Python361x64\wfastcgi.py"
           resourceType="Unspecified" requireAccess="Script"/>
    </handlers>
  </system.webServer>
</configuration>

这是一个带有应用程序设置的 FastCGI 处理程序示例。

applicationHost.xdt文件还有另一种方式,你可以参考这里:Xdt transform samples。要将文件夹添加到 PATH,下面是一个示例。

<?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="FOO" value="BAR" xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />    
        <add name="PATH" value="%PATH%;%HOME%\FolderOnPath" xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />    
      </environmentVariables>
    </runtime> 
  </system.webServer> 
</configuration> 

【讨论】:

以上是关于如何在 azure python 应用服务中将目录添加到 PATH的主要内容,如果未能解决你的问题,请参考以下文章

如何在 Azure 逻辑应用中将 blob 文件内容转换为 .docx

如何在 Azure 应用服务中将 X509Certificate2 与 WCF 一起使用

如何在 Flutter 移动应用中将 Azure AD 用户登录到 Firebase?

Azure:使用容器创建存储帐户并在 Python 中将 blob 上传到其中

如何在Azure Web Apps中将redirect_uri协议设置为HTTPS

如何在 Azure Notification Hub 中将 iOS 设备注册的到期日期设置为 31-12-9999 23:59:59?