在 Azure 应用程序服务上使用 python 3.6 - 尽管它作为扩展安装但无法正常工作
Using python 3.6 on azure app services - not working despite it is installed as extension
我遇到了使用外部 Git 存储库 (Bitbucket) 将 Django 应用程序(确切地说是 wagtail)部署到 Azure Web 服务的挑战。我想使用 Python 3.6.1,因此我按照 Managing Python on Azure App Service manual
中的说明进行操作
- 我安装了 python 3.6.1 扩展
- 我在我的应用程序的根目录中创建了 web.config 文件(我检查并上传到服务器)
但是,部署失败并显示消息
Detecting Python runtime from runtime.txt
Unsupported runtime: python-3.6.1
Supported runtime values are:
python-2.7
python-3.4
An error has occurred during web site deployment.
\r\nD:\Program Files (x86)\SiteExtensions\Kudu.61008.3066\bin\Scripts\starter.cmd "D:\home\site\deployments\tools\deploy.cmd"
我的 web.config 文件
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="PYTHONPATH" value="D:\home\site\wwwroot"/>
<!-- Django apps only -->
<add key="WSGI_HANDLER" value="django.core.wsgi.get_wsgi_application()"/>
<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>
路径没问题,下面是来自 Kudu 控制台的 ls
D:\home\python361x64>ls
DLLs
Lib
Scripts
__pycache__
python.exe
python3.dll
python36.dll
pythonw.exe
sitecustomize.py
vcruntime140.dll
wfastcgi.py
部署过程似乎没有考虑我拥有的 web.config 文件,或者我通过扩展安装的 python 版本不可见。
能否请您告诉我可能的问题出在哪里?
此致,
康拉德
我试图重现您的问题,但 failed.I 尝试将我自己的 django web app
部署到 azure 并且成功了。
你可以参考我的步骤,看看你是否遗漏了什么。
第 1 步: 按照 official tutorial 创建您的 Azure Web 应用。
步骤 2: 添加 Python 扩展名。
步骤 3: 添加 web.config
文件并部署您的网络应用程序。
<configuration>
<appSettings>
<add key="WSGI_HANDLER" value="<your 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\python361x64\python.exe|D:\home\python361x64\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>
第 4 步: 在您的 python extension environment
.
中安装 pip plugin
第 5 步: 安装 django
模块和您要使用的其他模块。
您可以参考一些类似的 SO 线程。
- Only getting Your App Service app has been created - after deploying to azure
希望对你有帮助。
经过几个小时的激战,我终于如愿运行了这个混蛋;)
谢谢@Jay Gong 的输入,本教程逐步向我展示了一些东西。
runtime.txt
文件,我在根文件夹中,是第一个问题。由于3.6版本的python是通过扩展安装的,实际上部署过程中并不存在这个v.(它"knows"只有2.7和3.4)。所以第一步是删除这个文件。
当 runtime.txt
被删除时,部署过程一直在使用 python 3.4,并且无法安装来自 requirements.txt
文件的依赖项之一(可能是因为python 的旧版本)。所以下一步是添加 .skipPythonDeployment,以避免自动安装需求并通过 kudu 控制台手动安装。在我们的 python env 文件夹中(在我的例子中 D:\home\python361x64
)以下命令被启动
python.exe -m pip install --upgrade -r D:\home\site\wwwroot\requirements.txt
所有依赖项都已正确安装。
部署后,在网络浏览器中启动应用程序显示消息 The page cannot be displayed because an internal server error has occurred.
。下一步是收集有关该问题的更多信息,因此我在 web.config
文件中添加了一些新行:
....
<system.webServer>
....
<httpErrors errorMode="Detailed"></httpErrors>
</system.webServer>
<system.web>
....
<customErrors mode="Off" />
</system.web>
多亏了这个,我才能够检查是什么导致了这个问题。在我的例子中,它是 web.config
中的 WSGI_HANDLER
值。我将它设置为正确的值(对于鹡鸰它是 <app_name>.wsgi.application
然后它开始工作。
感谢大家的支持。
我正在发布 Calfy 答案的缺失部分。
<add key="WSGI_ALT_VIRTUALENV_HANDLER" value="app.wsgi_app" />
<add key="WSGI_ALT_VIRTUALENV_ACTIVATE_THIS" value="D:\home\python361x64\python.exe" />
<add key="WSGI_HANDLER" value="ptvs_virtualenv_proxy.get_venv_handler()"/>
app.wsgi_app 实际上是 app.py 在你的文件夹中,据我所知,它一定是一个 wsgi 应用程序,而不是常规的 python 应用程序..(我也使用了 cherrypy mod 这里)这个示例应用程序是从互联网的某个地方复制的。
import sys
import cherrypy
class Hello(object):
@cherrypy.expose
@cherrypy.tools.response_headers(headers=[('Content-Type', 'text/plain')])
def index(self):
message = """\
Hello Azure!
Python: {python_version}
CherryPy: {cherrypy_version}
More info: http://blog.cincura.net/id/233498
"""
return message.format(python_version=sys.version, cherrypy_version=cherrypy.__version__)
wsgi_app = cherrypy.Application(Hello(), '/')
if __name__ == '__main__':
from wsgiref.simple_server import make_server
httpd = make_server('', 6600, wsgi_app)
httpd.serve_forever()
我遇到了使用外部 Git 存储库 (Bitbucket) 将 Django 应用程序(确切地说是 wagtail)部署到 Azure Web 服务的挑战。我想使用 Python 3.6.1,因此我按照 Managing Python on Azure App Service manual
中的说明进行操作- 我安装了 python 3.6.1 扩展
- 我在我的应用程序的根目录中创建了 web.config 文件(我检查并上传到服务器)
但是,部署失败并显示消息
Detecting Python runtime from runtime.txt
Unsupported runtime: python-3.6.1
Supported runtime values are:
python-2.7
python-3.4
An error has occurred during web site deployment.
\r\nD:\Program Files (x86)\SiteExtensions\Kudu.61008.3066\bin\Scripts\starter.cmd "D:\home\site\deployments\tools\deploy.cmd"
我的 web.config 文件
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="PYTHONPATH" value="D:\home\site\wwwroot"/>
<!-- Django apps only -->
<add key="WSGI_HANDLER" value="django.core.wsgi.get_wsgi_application()"/>
<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>
路径没问题,下面是来自 Kudu 控制台的 ls
D:\home\python361x64>ls
DLLs
Lib
Scripts
__pycache__
python.exe
python3.dll
python36.dll
pythonw.exe
sitecustomize.py
vcruntime140.dll
wfastcgi.py
部署过程似乎没有考虑我拥有的 web.config 文件,或者我通过扩展安装的 python 版本不可见。
能否请您告诉我可能的问题出在哪里?
此致,
康拉德
我试图重现您的问题,但 failed.I 尝试将我自己的 django web app
部署到 azure 并且成功了。
你可以参考我的步骤,看看你是否遗漏了什么。
第 1 步: 按照 official tutorial 创建您的 Azure Web 应用。
步骤 2: 添加 Python 扩展名。
步骤 3: 添加 web.config
文件并部署您的网络应用程序。
<configuration>
<appSettings>
<add key="WSGI_HANDLER" value="<your 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\python361x64\python.exe|D:\home\python361x64\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>
第 4 步: 在您的 python extension environment
.
pip plugin
第 5 步: 安装 django
模块和您要使用的其他模块。
您可以参考一些类似的 SO 线程。
- Only getting Your App Service app has been created - after deploying to azure
希望对你有帮助。
经过几个小时的激战,我终于如愿运行了这个混蛋;)
谢谢@Jay Gong 的输入,本教程逐步向我展示了一些东西。
runtime.txt
文件,我在根文件夹中,是第一个问题。由于3.6版本的python是通过扩展安装的,实际上部署过程中并不存在这个v.(它"knows"只有2.7和3.4)。所以第一步是删除这个文件。当
runtime.txt
被删除时,部署过程一直在使用 python 3.4,并且无法安装来自requirements.txt
文件的依赖项之一(可能是因为python 的旧版本)。所以下一步是添加 .skipPythonDeployment,以避免自动安装需求并通过 kudu 控制台手动安装。在我们的 python env 文件夹中(在我的例子中D:\home\python361x64
)以下命令被启动
python.exe -m pip install --upgrade -r D:\home\site\wwwroot\requirements.txt
所有依赖项都已正确安装。部署后,在网络浏览器中启动应用程序显示消息
The page cannot be displayed because an internal server error has occurred.
。下一步是收集有关该问题的更多信息,因此我在web.config
文件中添加了一些新行:.... <system.webServer> .... <httpErrors errorMode="Detailed"></httpErrors> </system.webServer> <system.web> .... <customErrors mode="Off" /> </system.web>
多亏了这个,我才能够检查是什么导致了这个问题。在我的例子中,它是
web.config
中的WSGI_HANDLER
值。我将它设置为正确的值(对于鹡鸰它是<app_name>.wsgi.application
然后它开始工作。
感谢大家的支持。
我正在发布 Calfy 答案的缺失部分。
<add key="WSGI_ALT_VIRTUALENV_HANDLER" value="app.wsgi_app" />
<add key="WSGI_ALT_VIRTUALENV_ACTIVATE_THIS" value="D:\home\python361x64\python.exe" />
<add key="WSGI_HANDLER" value="ptvs_virtualenv_proxy.get_venv_handler()"/>
app.wsgi_app 实际上是 app.py 在你的文件夹中,据我所知,它一定是一个 wsgi 应用程序,而不是常规的 python 应用程序..(我也使用了 cherrypy mod 这里)这个示例应用程序是从互联网的某个地方复制的。
import sys
import cherrypy
class Hello(object):
@cherrypy.expose
@cherrypy.tools.response_headers(headers=[('Content-Type', 'text/plain')])
def index(self):
message = """\
Hello Azure!
Python: {python_version}
CherryPy: {cherrypy_version}
More info: http://blog.cincura.net/id/233498
"""
return message.format(python_version=sys.version, cherrypy_version=cherrypy.__version__)
wsgi_app = cherrypy.Application(Hello(), '/')
if __name__ == '__main__':
from wsgiref.simple_server import make_server
httpd = make_server('', 6600, wsgi_app)
httpd.serve_forever()