【问题标题】:Why is the azure app service django deploy keep failing?为什么 azure app service django deploy 总是失败?
【发布时间】:2018-03-08 12:38:32
【问题描述】:

已经 1 个月了,我仍然无法弄清楚我或 azure 中的应用服务出了什么问题。

我使用了 python 2.7 和 django 1.11.3,带有这个 requirements.txt

beautifulsoup4==4.6.0 证书==2017.7.27.1 chardet==3.0.4 Django==1.11.5 idna==2.6 olefile==0.44 枕头==4.2.1 pytz==2017.2 请求==2.18.4 urllib3==1.22

当我使用本地 Git 存储库部署到 Azure Web 服务(Python2.7,Windows)时,它似乎没有安装要求。

我尝试了 wheel 但它没有做任何事情,并且通过 scm powershell 我未能安装任何要求,例如:

Python -m pip install django

它没有给我权限错误。

【问题讨论】:

    标签: python django azure azure-web-app-service


    【解决方案1】:

    在 Azure WebApps 上,Python 默认安装在路径 D:\Python27\ 上,除了路径 D:\home\ 之外,用户无权执行任何写入操作,例如命令 pip install <packages> 将 Python 包安装到 libs

    所以首先你需要通过 Kudu 站点扩展在路径D:\home 安装一个新的 Python 运行时,如下图。

    然后就可以看到D:\home下的Python目录,你有写操作权限。

    如需安装所需的 Python 包,请执行以下命令安装 pip 工具。

    D:\home> cd Python27
    D:\home\Python27> curl -o get-pip.py https://bootstrap.pypa.io/get-pip.py
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    
    100 1558k  100 1558k    0     0  5069k      0 --:--:-- --:--:-- --:--:-- 6546k
    D:\home\Python27> python get-pip.py
    Requirement already up-to-date: pip in d:\home\python27\lib\site-packages
    Collecting wheel
      Downloading wheel-0.30.0-py2.py3-none-any.whl (49kB)
    Installing collected packages: wheel
    Successfully installed wheel-0.30.0
    

    接下来,你可以通过python -m pip install <package-name>安装这些包,比如python -m pip install django==1.11.5如下。

    D:\home\Python27> python -m pip install django==1.11.5
    Collecting django==1.11.5
      Downloading Django-1.11.5-py2.py3-none-any.whl (6.9MB)
    Collecting pytz (from django==1.11.5)
      Downloading pytz-2017.2-py2.py3-none-any.whl (484kB)
    Installing collected packages: pytz, django
    

    正如官方文档所说,对于Troubleshooting - Package Installation,如下,对于包Pillow,需要编译C代码。

    疑难解答 - 软件包安装

    在 Azure 上运行时,某些包可能无法使用 pip 安装。可能只是因为该包在 Python 包索引中不可用。可能需要编译器(在 Azure 应用服务中运行 Web 应用的计算机上没有编译器)。

    您需要在 Kudu CMD 上通过命令curl -o <wheel-file-name> <wheel-file-url>here 下载包轮文件,并通过命令python -m pip install <wheel-file-name> 安装它们。

    安装完所有包后,你可以将你的django webapp上传到D:\home\site\wwwroot,这个路径下的文件结构看起来像官方的sample,包含了PTVS在VS 2017上创建的app<your-django-project-name>这些目录。

    最后,请配置您的web.config 文件以使您的应用正常运行。

    <configuration>
      <appSettings>
        <add key="WSGI_HANDLER" value="<your-django-project-name>.wsgi.application"/>
        <add key="PYTHONPATH" value="D:\home\site\wwwroot"/>
        <add key="WSGI_LOG" value="D:\home\LogFiles\wfastcgi.log"/>
      </appSettings>
      <system.webServer>
        <handlers>
          <add name="PythonHandler" path="handler.fcgi" verb="*" modules="FastCgiModule" scriptProcessor="D:\home\Python27\python.exe|D:\home\Python27\wfastcgi.py" 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>
    </configuration>
    

    希望对您有所帮助。有任何问题,请随时告诉我。

    【讨论】:

    • 嘿,现在我得到“页面无法显示,因为发生了内部服务器错误。”,部署时似乎没有错误
    • @HariAnugrah 请查看D:\home\LogFiles\wfastcgi.log 路径中的日志并更新您关于此问题的帖子。
    • 谢谢,我解决了问题问题是,azure app服务默认使用virtualenv,所以requirements.txt包会自动安装到virtualenv中的python...所以我只是编辑部署。 cmd 安装对 python 的要求(扩展)...非常感谢
    猜你喜欢
    • 2013-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-12
    • 2018-06-10
    • 1970-01-01
    相关资源
    最近更新 更多