为什么 azure 应用服务 django deploy 总是失败? [英] Why is the azure app service django deploy keep failing?

查看:14
本文介绍了为什么 azure 应用服务 django deploy 总是失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

<块引用>

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

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

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

<块引用>

Python -m pip install django

它没有给我权限错误.

解决方案

在 Azure WebApps 上,Python 默认安装在路径 D:Python27 中,该路径不允许用户进行任何写入像命令 pip install 将 Python 包安装到 libs 之类的操作,除了在路径 D:home 下.

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

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

要安装你想要的 Python 包,请执行以下命令来安装 pip 工具.

D:home>光盘 Python27D:homePython27>curl -o get-pip.py https://bootstrap.pypa.io/get-pip.py% Total % Received % Xferd 平均速度时间时间时间电流下载上传总花费的剩余速度100 1558k 100 1558k 0 0 5069k 0 --:--:-- --:--:-- --:--:-- 6546kD:homePython27>蟒蛇获取pip.py要求已经是最新的:d:homepython27libsite-packages 中的 pip收集轮下载wheel-0.30.0-py2.py3-none-any.whl (49kB)安装收集到的包:wheel成功安装wheel-0.30.0

接下来可以通过python -m pip install 安装这些包,比如python -m pip install django==1.11.5 如下.

D:homePython27>python -m pip install django==1.11.5收集django==1.11.5下载 Django-1.11.5-py2.py3-none-any.whl (6.9MB)收集 pytz(来自 django==1.11.5)下载 pytz-2017.2-py2.py3-none-any.whl (484kB)安装收集到的包:pytz、django

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

<块引用>

疑难解答 - 软件包安装

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

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

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

最后,请配置您的 web.config 文件以使您的应用程序正常工作.

<预><代码><配置><应用设置><add key="WSGI_HANDLER" value="<your-django-project-name>.wsgi.application"/><add key="PYTHONPATH" value="D:homesitewwwroot"/><add key="WSGI_LOG" value="D:homeLogFileswfastcgi.log"/></appSettings><system.webServer><处理程序><add name="PythonHandler" path="handler.fcgi" verb="*" modules="FastCgiModule" scriptProcessor="D:homePython27python.exe|D:homePython27wfastcgi.py"resourceType="Unspecified" requireAccess="Script"/></处理程序><重写><规则><规则名称="静态文件" stopProcessing="true"><条件><add input="true" pattern="false"/></条件></规则><规则名称="配置 Python" stopProcessing="true"><match url="(.*)" ignoreCase="false"/><条件><add input="{REQUEST_URI}" pattern="^/static/.*" ignoreCase="true" negate="true"/></条件><action type="Rewrite" url="handler.fcgi/{R:1}" appendQueryString="true"/></规则></规则></rewrite></system.webServer></配置>

希望有帮助.有任何问题,请随时告诉我.

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

I used python 2.7 and django 1.11.3, with this requirements.txt

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

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

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

It gave me no permission error.

解决方案

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.

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

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

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

D:home> cd Python27
D:homePython27> 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:homePython27> python get-pip.py
Requirement already up-to-date: pip in d:homepython27libsite-packages
Collecting wheel
  Downloading wheel-0.30.0-py2.py3-none-any.whl (49kB)
Installing collected packages: wheel
Successfully installed wheel-0.30.0

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

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

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

After installed all packages, you can upload your django webapp to D:homesitewwwroot, 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.

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:homesitewwwroot"/>
    <add key="WSGI_LOG" value="D:homeLogFileswfastcgi.log"/>
  </appSettings>
  <system.webServer>
    <handlers>
      <add name="PythonHandler" path="handler.fcgi" verb="*" modules="FastCgiModule" scriptProcessor="D:homePython27python.exe|D:homePython27wfastcgi.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 应用服务 django deploy 总是失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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