Using python 3.6 on azure app services - not working despite it is installed as extension
After a couple of hours of fighting, I finally managed to run this bastard as expected ;)
Thanks, @Jay Gong for your input as going step by step with this tutorial showed me a couple of things.
runtime.txt
file, which I had in the root folder, was the first issue. As 3.6 version of python is installed via extensions, in fact, deployment process does not now that this v. exists (it "knows" only 2.7 and 3.4). So the first step was to get rid of this file.When
runtime.txt
had been removed, deployment process has been using python 3.4 and was failing on installation one of the dependencies fromrequirements.txt
file (probably because of the older version of python). So the next step was to add .skipPythonDeployment, to avoid automatic installation of requirements and install those manually by kudu console. In folder with our python env (in my caseD:\home\python361x64
) following command was launchedpython.exe -m pip install --upgrade -r D:\home\site\wwwroot\requirements.txt
All dependencies were installed correctly.After deploy, launching an app in a web browser showed message
The page cannot be displayed because an internal server error has occurred.
. Next step was to gather more info about the issue, so I have added a few new lines inweb.config
file:....<system.webServer>.... <httpErrors errorMode="Detailed"></httpErrors></system.webServer><system.web> .... <customErrors mode="Off" /></system.web>
Thanks to that, I was able to check what is causing the issue. In my case, it was a
WSGI_HANDLER
value inweb.config
. I set it to a correct value (for wagtail it was<app_name>.wsgi.application
and then it started working.
Thank you guys for all your support.
I tried to reproduce your issue but failed.I tried to deploy my own django web app
to azure and it works.
You could refer to my steps and check if you you missed something.
Step 1: Follow the official tutorial to create your azure web app.
Step 2: Add Python extension.
Step 3: Add web.config
file and deploy your web app.
<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>
Step 4: Install pip plugin
in your python extension environment
.
Step 5: Install django
module and other modules you want to use.
There are some similar SO threads you could refer to.
- Only getting Your App Service app has been created - after deploying to azure
- Django web app deploy in Azure via Visual Studio 2017
Hope it helps you.
I am posting the missing parts of Calfy answer.
<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 is actually app.py in your folder and from what i understand it must be an wsgi app not regular python app.. (i also used cherrypy mod here) this sample app is copied somewhere from internet.
import sysimport cherrypyclass 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()