Azure部署未安装requirements.txt中列出的Python程序包 [英] Azure deployment not installing Python packages listed in requirements.txt

查看:70
本文介绍了Azure部署未安装requirements.txt中列出的Python程序包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次将Flask Web应用程序部署到Azure的经验.我遵循了教程一个>.

This is my first experience deploying a Flask web app to Azure. I followed this tutorial.

他们拥有的默认演示应用程序适合我.

The default demo app they have works fine for me.

然后,我通过git推送了我的Flask应用.日志显示部署成功.但是,当我通过应用程序属性"中提供的链接浏览托管的应用程序时,出现500错误,如下所示:

Afterwards, I pushed my Flask app via git. The log shows deployment was successful. However, when I browse the hosted app via link provided in "Application Properties", I get a 500 error as follows:

由于内部服务器错误而无法显示该页面发生了.

The page cannot be displayed because an internal server error has occurred.

最可能的原因:IIS收到了请求;但是,内部处理请求期间发生错误.的根本原因此错误取决于哪个模块处理请求以及发生此错误时,在工作进程中发生的错误.IIS不是能够访问网站或应用程序的web.config文件.如果NTFS权限设置不正确,可能会发生这种情况.IIS原为无法处理网站或应用程序的配置.这经过身份验证的用户没有使用此DLL的权限.这请求被映射到托管处理程序,但.NET可扩展性功能尚未安装.

Most likely causes: IIS received the request; however, an internal error occurred during the processing of the request. The root cause of this error depends on which module handles the request and what was happening in the worker process when this error occurred. IIS was not able to access the web.config file for the Web site or application. This can occur if the NTFS permissions are set incorrectly. IIS was not able to process configuration for the Web site or application. The authenticated user does not have permission to use this DLL. The request is mapped to a managed handler but the .NET Extensibility Feature is not installed.

通过KUDU浏览wwwroot,我唯一能看到的是,尽管wwwroot中存在"requirements.txt"文件,但我在本地虚拟环境中安装的所有软件包都没有安装在Azure上.

The only off-base thing I can see by browsing the wwwroot via KUDU is that none of the packages I have installed in my local virtual environment are installed on Azure despite the existence of the "requirements.txt" file in wwwroot.

我的理解是,在GIT成功推送后,Azure会pip安装它在requirements.txt中找到的任何不存在的程序包.但这似乎并没有发生在我身上.

My understanding is that Azure would pip install any non existent package that it finds in the requirements.txt upon GIT successful push. But it doesn't seem to be happening for me.

我做错什么了吗?缺少包装只是一种症状,还是可能是引起问题的原因?

Am I doing something wrong and the missing packages is just a symptom or could it be the cause the issue?

注意:

  • 我的Flask应用在本地(Linux)和第三方VPS上都能正常运行

  • My Flask app works fine locally (linux) and on a 3rd party VPS

我从头开始重新部署了几次,直到无济于事(我使用本地GIT方法)

I redeployed several times starting from scratch to no avail (I use local GIT method)

我在本地克隆了Azure Flask演示应用程序,仅更改了应用程序文件夹并推回Azure,但没有成功.

I cloned the Azure Flask demo app locally, changed just the app folder and pushed back to Azure, yet no success.

Azure设置为与本地虚拟环境相同的Python 2.7

Azure is set to Python 2.7 same as my virtual env locally

按照上面链接的教程中的建议,我删除了"env"文件夹,然后重新部署以欺骗Azure重新安装虚拟环境.它确实有,但是有它自己的默认软件包,而不是我的requirements.txt中的那个.

As suggested in the tutorial linked above, I deleted the "env" folder and redeployed to trick Azure to reinstall the virtual env. It did but with its own default packages not the one in my requirements.txt.

我的requirements.txt具有以下内容:

My requirements.txt has the following:

bcrypt == 3.1.0 cffi == 1.7.0 click == 6.6 Flask == 0.11.1 Flask-Bcrypt == 0.7.1Flask-Login == 0.3.2 Flask-SQLAlchemy == 2.1 Flask-WTF == 0.12itsdangerous == 0.24 Jinja2 == 2.8 MarkupSafe == 0.23 pycparser == 2.14PyMySQL == 0.7.7 python-http-client == 1.2.3六个== 1.10.0 smtpapi == 0.3.1SQLAlchemy == 1.0.14 Werkzeug == 0.11.10 WTForms == 2.1

bcrypt==3.1.0 cffi==1.7.0 click==6.6 Flask==0.11.1 Flask-Bcrypt==0.7.1 Flask-Login==0.3.2 Flask-SQLAlchemy==2.1 Flask-WTF==0.12 itsdangerous==0.24 Jinja2==2.8 MarkupSafe==0.23 pycparser==2.14 PyMySQL==0.7.7 python-http-client==1.2.3 six==1.10.0 smtpapi==0.3.1 SQLAlchemy==1.0.14 Werkzeug==0.11.10 WTForms==2.1

推荐答案

Azure Web Apps将运行 deploy.cmd 脚本作为部署任务,以控制将在运行期间运行哪些命令或任务.部署.

As Azure Web Apps will run a deploy.cmd script as the deployment task to control which commands or tasks will be run during the deployment.

您可以使用Azure-CLI azure站点部署脚本--python 的命令来获取python应用程序的部署任务脚本.

You can use the command of Azure-CLI azure site deploymentscript --python to get the python applications' deployment task script.

您可以在此 deploy.cmd 程序中找到以下脚本:

And you can find the following script in this deploy.cmd sciprt:

IF NOT EXIST "%DEPLOYMENT_TARGET%\requirements.txt" goto postPython
IF EXIST "%DEPLOYMENT_TARGET%\.skipPythonDeployment" goto postPython

echo Detected requirements.txt.  You can skip Python specific steps with a .skipPythonDeployment file.

因此, .skipPythonDeployment 将跳过部署任务中的以下所有步骤,包括创建虚拟环境.

So the .skipPythonDeployment will skip all the following steps in deployment task, including creating virtual environment.

您可以尝试从应用程序中删除 .skipPythonDeployment ,然后重试.

You can try to remove .skipPythonDeployment from your application, and try again.

此外,请参考 https://github.com/projectkudu/kudu/wiki/Custom-Deployment-Script 了解更多信息.

Additionally, please refer to https://github.com/projectkudu/kudu/wiki/Custom-Deployment-Script for more info.

这篇关于Azure部署未安装requirements.txt中列出的Python程序包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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