0

I have been trying to deploy a web application to azure using python as the backend for the web application however anytime i try to deploy from local git it works correctly however the application fails.

After trying to run the script directly from the application console on azure :

Python hostingstart.py

Results in an error:

No module Flask found

After realising this, i tried to run pip in the command-line and it seems azure has python version 3.6.6 installed which is fine, but i cannot call pip directly from the commandline.

However it does "deploy correctly" when i do a git push from local:

remote: Requirement already satisfied: click==6.7 in d:\home\site\wwwroot\env\lib\site-packages (from -r requirements.txt (line 1)) (6.7)
remote: Requirement already satisfied: Flask==1.0.2 in d:\home\site\wwwroot\env\lib\site-packages (from -r requirements.txt (line 2)) (1.0.2)
remote: Requirement already satisfied: itsdangerous==0.24 in d:\home\site\wwwroot\env\lib\site-packages (from -r requirements.txt (line 3)) (0.24)
remote: Requirement already satisfied: Jinja2==2.10 in d:\home\site\wwwroot\env\lib\site-packages (from -r requirements.txt (line 4)) (2.10)
remote: Requirement already satisfied: MarkupSafe==1.0 in d:\home\site\wwwroot\env\lib\site-packages (from -r requirements.txt (line 5)) (1.0)
remote: Requirement already satisfied: Werkzeug==0.14.1 in d:\home\site\wwwroot\env\lib\site-packages (from -r requirements.txt (line 6)) (0.14.1)
remote: You are using pip version 10.0.1, however version 19.0.3 is available.
remote: You should consider upgrading via the 'python -m pip install --upgrade pip' command.
remote: Finished successfully.
remote: Running post deployment command(s)...
remote: Deployment successful.

It seems like there is a step I am missing as I have provided my requirements in requirements.txt and azure seems to suggest they are being installed as part of the deployment...although im unsure how as pip isnt installed in the machine im accessing via the web console....can anyone explain what is going on?

Other notes that might be useful:

I deploy the application through the azure web ui not via the az webapp up as i did not want to deploy into a new linux container in a new group, i wanted the resource to be in a specific pre-defined group (not sure if this is relevant as the web app is infact up despite not resolving the dependencies).

The default deployed web app works fine showing : This web site is running Python 3.6.6.

D3181
  • 2,037
  • 5
  • 19
  • 44
  • Are you running the `python` from the correct `env` ? – han solo Mar 27 '19 at 15:16
  • I am unsure... I followed this guide : https://learn.microsoft.com/en-gb/azure/app-service/containers/quickstart-python?toc=%2Fpython%2Fazure%2FTOC.json minus the webapp up part as stated before...from the console on azure i have the files from the example, plus an environment folder azure created, though the example didnt state the need to specify an environment – D3181 Mar 27 '19 at 15:19
  • You seem to be installing the requirements to a `venv` as mentioned in the guide. So did you run `python` like [this](https://learn.microsoft.com/en-gb/azure/app-service/containers/quickstart-python?toc=%2Fpython%2Fazure%2FTOC.json#run-the-app-locally) – han solo Mar 27 '19 at 15:22
  • Yeh, i just retried the top part: python3 -m venv venv source venv/bin/activate pip install -r requirements.txt FLASK_APP=application.py flask run - and then did a git push, the folders appear once again in the azure console : env, venv folders but the web app still does not find the flask module – D3181 Mar 27 '19 at 15:29

1 Answers1

1

I see you were deploying a Flask App to IIS on Azure WebApp for Windows, not to a container of Azure WebApp for Linux, but you followed the offical tutorial for Linux deployment.

So you can try to follow my answers for these SO threads as below to deploy it.

  1. Hosting Flask(Python) app throws CGI error
  2. Publishing Flask Web App on Azure
  3. Publishing MVC app that uses python script

The steps is roughly like below:

  1. Upload or git push your app.
  2. Install a Python extension in your webapp via Kudu.
  3. To install pip for the Python extension you installed before.
  4. Use pip to install these necessary dependencies, like flask or others defined in requirements.txt.
  5. Create a web.config file and configure it for IIS to start up your flask app.
Peter Pan
  • 23,476
  • 4
  • 25
  • 43