为什么Azure App Service django部署会持续失败? [英] Why is the azure app service django deploy keep failing?

查看:78
本文介绍了为什么Azure App Service django部署会持续失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已经1个月了,我仍然无法确定我或天蓝色的应用程序服务出了什么问题.

It's been 1 month and I still can't figure out what's wrong with me or app service in azure.

在此要求下,我使用了python 2.7和django 1.11.3.txt

I used python 2.7 and django 1.11.3, with this 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

beautifulsoup4==4.6.0 certifi==2017.7.27.1 chardet==3.0.4 Django==1.11.5 idna==2.6 olefile==0.44 Pillow==4.2.1 pytz==2017.2 requests==2.18.4 urllib3==1.22

当我将本地Git存储库部署到Azure Web Service(Python2.7,Windows)时,似乎没有安装要求.

When I deploy with Local Git Repository to Azure Web Service(Python2.7, Windows) it doesn't seems to install the requirements.

我尝试了wheel,但是它什么也没做,通过scm powershell我无法安装任何要求,例如:

I tried wheel but it doesn't do anything, and via scm powershell I failed to install any of the requirements, example:

Python -m pip install django

Python -m pip install django

它没有给我权限错误.

推荐答案

在Azure WebApp上,默认情况下将Python安装在路径D:\Python27\上,该路径无权让用户执行任何命令(如命令pip install <packages>)来安装Python打包到libs,除了在D:\home\路径下.

On Azure WebApps, Python is installed default at the path D:\Python27\ which has no permission for users to do any write operations like command pip install <packages> to install Python packages to libs, besides under the path D:\home\.

所以首先,您需要通过Kudu网站扩展在路径D:\home上安装新的Python运行时,如下图.

So first you need to install a new Python runtime at the path D:\home via Kudu site extensions, as the figure below.

然后,您可以在D:\home下看到您具有写操作权限的Python目录.

Then, you can see the Python directory under D:\home which you have the write operation permission.

要安装所需的Python软件包,请执行以下命令以安装pip工具.

For installing Python packages you want, do the commands as below to install pip tool.

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)安装这些软件包.

The next, you can install these packages via python -m pip install <package-name>, such as python -m pip install django==1.11.5 as below.

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

如官方文档所述,对于

As the offical document said, for Troubleshooting - Package Installation, as below, like for package Pillow need compiler for C code.

故障排除-软件包安装

Troubleshooting - Package Installation

在Azure上运行时,某些软件包可能无法使用pip进行安装.可能仅仅是该软件包在Python软件包索引上不可用.可能是需要编译器(在Azure App Service中运行Web应用程序的计算机上没有编译器).

Some packages may not install using pip when run on Azure. It may simply be that the package is not available on the Python Package Index. It could be that a compiler is required (a compiler is not available on the machine running the web app in Azure App Service).

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

You need to download package wheel files from here via command curl -o <wheel-file-name> <wheel-file-url> on Kudu CMD, and install them via command python -m pip install <wheel-file-name>.

安装所有软件包后,您可以将django webapp上传到D:\home\site\wwwroot,此路径下的文件结构看起来像官方的

After installed all packages, you can upload your django webapp to D:\home\site\wwwroot, the file structure under this path looks like the offical sample that includes these directories app, <your-django-project-name> created by PTVS on VS 2017.

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

Finally, please configure your web.config file to make your app works.

<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>

希望它会有所帮助.如有任何疑问,请随时告诉我.

Hope it helps. Any concern, please feel free to let me know.

这篇关于为什么Azure App Service django部署会持续失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆