Azure deployment not installing Python packages listed in requirements.txt
<p>This is my first experience deploying a Flask web app to Azure.
I followed this <a href="https://azure.microsoft.com/en-us/documentation/articles/web-sites-python-create-deploy-flask-app/" rel="nofollow">tutorial</a>.  </p>

<p>The default demo app they have works fine for me. </p>

<p>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:</p>

<blockquote>
  <p>The page cannot be displayed because an internal server error has
  occurred.</p>
  
  <p>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.</p>
</blockquote>

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

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

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

<p>Notes:</p>

<ul>
<li><p>My Flask app works fine locally (linux) and on a 3rd party VPS</p></li>
<li><p>I redeployed several times starting from scratch to no avail (I use local GIT method)</p></li>
<li><p>I cloned the Azure Flask demo app locally, changed just the app folder and pushed back to Azure, yet no success.</p></li>
<li><p>Azure is set to Python 2.7 same as my virtual env locally</p></li>
<li><p>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.</p></li>
</ul>

<p>My requirements.txt has the following:</p>

<blockquote>
  <p>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</p>
</blockquote>

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

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

<p>And you can find the following script in this <code>deploy.cmd</code> sciprt:</p>

<pre><code>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.
</code></pre>

<p>So the <code>.skipPythonDeployment</code> will skip all the following steps in deployment task, including creating virtual environment.</p>

<p>You can try to remove <code>.skipPythonDeployment</code> from your application, and try again.</p>

<p>Additionally, please refer to <a href="https://github.com/projectkudu/kudu/wiki/Custom-Deployment-Script" rel="nofollow">https://github.com/projectkudu/kudu/wiki/Custom-Deployment-Script</a> for more info.</p>

python azure deployment flask requirements.txt