0

I thought it's easy to deploy a python api project to somewhere. BUT I was wrong, I cannot deploy to any platforms.

So far I have tried:

  1. Azure, Webapp and Function App
  2. PythonAnywhere
  3. Heroku

They all have issues when I'm trying to install dependency packages for this one: scikit-fmm

here is the error message:

Python Version is 3.7.10 Linux

pip install scikit-fmm

Collecting scikit-fmm
  Using cached scikit-fmm-2021.2.2.tar.gz (419 kB)
Requirement already satisfied: numpy>=1.0.2 in /usr/local/lib/python3.7/site-packages (from scikit-fmm) (1.18.1)
Building wheels for collected packages: scikit-fmm
  Building wheel for scikit-fmm (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/local/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-bihhvskj/scikit-fmm_13c74930cf4a4cfc949e4a3e9
d5f6e54/setup.py'"'"'; __file__='"'"'/tmp/pip-install-bihhvskj/scikit-fmm_13c74930cf4a4cfc949e4a3e9d5f6e54/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"',
 open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-
5ebu19pu
       cwd: /tmp/pip-install-bihhvskj/scikit-fmm_13c74930cf4a4cfc949e4a3e9d5f6e54/
  Complete output (32 lines):
  running bdist_wheel
  running build
  running config_cc
  unifing config_cc, config, build_clib, build_ext, build commands --compiler options
  running config_fc
  unifing config_fc, config, build_clib, build_ext, build commands --fcompiler options
  running build_src
  build_src
  building extension "skfmm.cfmm" sources
  building extension "skfmm.pheap" sources
  build_src: building npy-pkg config files
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.7
  creating build/lib.linux-x86_64-3.7/skfmm
  copying skfmm/pfmm.py -> build/lib.linux-x86_64-3.7/skfmm
  copying skfmm/setup.py -> build/lib.linux-x86_64-3.7/skfmm

  copying skfmm/heap.py -> build/lib.linux-x86_64-3.7/skfmm
  copying skfmm/__init__.py -> build/lib.linux-x86_64-3.7/skfmm
  running build_ext
  customize UnixCCompiler
  customize UnixCCompiler using build_ext
  customize UnixCCompiler
  customize UnixCCompiler using build_ext
  building 'skfmm.cfmm' extension
  compiling C++ sources
  C compiler: g++ -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC

  creating build/temp.linux-x86_64-3.7/skfmm
  compile options: '-Iskfmm -I/usr/local/lib/python3.7/site-packages/numpy/core/include -I/usr/local/include/python3.7m -c'
  g++: skfmm/fmm.cpp
  error: Command "g++ -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -Iskfmm -I/usr/local/lib/python3.7/site-packages/numpy/
core/include -I/usr/local/include/python3.7m -c skfmm/fmm.cpp -o build/temp.linux-x86_64-3.7/skfmm/fmm.o -MMD -MF build/temp.linux-x86_64-3.7/skfmm/fmm.o.d"
 failed with exit status 127
  ----------------------------------------
  ERROR: Failed building wheel for scikit-fmm
  Running setup.py clean for scikit-fmm
Failed to build scikit-fmm
Installing collected packages: scikit-fmm
    Running setup.py install for scikit-fmm ... error
    ERROR: Command errored out with exit status 1:
     command: /usr/local/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-bihhvskj/scikit-fmm_13c74930cf4a4cfc949e4a3
e9d5f6e54/setup.py'"'"'; __file__='"'"'/tmp/pip-install-bihhvskj/scikit-fmm_13c74930cf4a4cfc949e4a3e9d5f6e54/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"
', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-re
cord-gku3heb3/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.7m/scikit-fmm
         cwd: /tmp/pip-install-bihhvskj/scikit-fmm_13c74930cf4a4cfc949e4a3e9d5f6e54/
    Complete output (28 lines):
Note: if you need to uninstall you should `pip install scikit-fmm` instead of using `setup.py install`
    running install
    running build
    running config_cc
    unifing config_cc, config, build_clib, build_ext, build commands --compiler options
    running config_fc
    unifing config_fc, config, build_clib, build_ext, build commands --fcompiler options
    running build_src
    build_src
    building extension "skfmm.cfmm" sources
    building extension "skfmm.pheap" sources
    build_src: building npy-pkg config files
    running build_py
    running build_ext
    customize UnixCCompiler
    customize UnixCCompiler using build_ext
    customize UnixCCompiler
    customize UnixCCompiler using build_ext
    building 'skfmm.cfmm' extension
    compiling C++ sources
    C compiler: g++ -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC

    creating build/temp.linux-x86_64-3.7/skfmm
    compile options: '-Iskfmm -I/usr/local/lib/python3.7/site-packages/numpy/core/include -I/usr/local/include/python3.7m -c'
    g++: skfmm/fmm.cpp
    error: Command "g++ -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -Iskfmm -I/usr/local/lib/python3.7/site-packages/nump
y/core/include -I/usr/local/include/python3.7m -c skfmm/fmm.cpp -o build/temp.linux-x86_64-3.7/skfmm/fmm.o -MMD -MF build/temp.linux-x86_64-3.7/skfmm/fmm.o.
d" failed with exit status 127
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/local/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-bihhvskj/s
cikit-fmm_13c74930cf4a4cfc949e4a3e9d5f6e54/setup.py'"'"'; __file__='"'"'/tmp/pip-install-bihhvskj/scikit-fmm_13c74930cf4a4cfc949e4a3e9d5f6e54/setup.py'"'"';
f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"
'))' install --record /tmp/pip-record-gku3heb3/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3
.7m/scikit-fmm Check the logs for full command output.

Update 1

Thanks to JasonPan's suggestion, I know have all dependencies installed on Azure web app.

My app deployment is also successful, but the website does not work. I checked the logs and found many errors:

2021-04-22T07:44:09.836453360Z [2021-04-22 07:44:09 +0000] [78] [ERROR] Retrying in 1 second.
2021-04-22T07:44:10.838153643Z [2021-04-22 07:44:10 +0000] [78] [ERROR] Connection in use: ('0.0.0.0', 8000)
2021-04-22T07:44:10.839051770Z [2021-04-22 07:44:10 +0000] [78] [ERROR] Retrying in 1 second.
2021-04-22T07:44:11.840184035Z [2021-04-22 07:44:11 +0000] [78] [ERROR] Can't connect to ('0.0.0.0', 8000)
2021-04-22T07:44:11.892574745Z [2021-04-22 07:44:11 +0000] [77] [INFO] Worker exiting (pid: 77)
2021-04-22T07:44:12.375216277Z [2021-04-22 07:44:12 +0000] [80] [INFO] Booting worker with pid: 80
2021-04-22T07:44:15.438983261Z  * Serving Flask app "app" (lazy loading)
2021-04-22T07:44:15.445347462Z  * Environment: production
2021-04-22T07:44:15.486186353Z    WARNING: This is a development server. Do not use it in a production deployment.
2021-04-22T07:44:15.486284356Z    Use a production WSGI server instead.
2021-04-22T07:44:15.486294356Z  * Debug mode: on
2021-04-22T07:44:15.486487762Z  * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
2021-04-22T07:44:15.486499263Z  * Restarting with stat
2021-04-22T07:44:16.191646039Z [2021-04-22 07:44:16 +0000] [81] [INFO] Starting gunicorn 20.0.4
2021-04-22T07:44:16.192867778Z [2021-04-22 07:44:16 +0000] [81] [ERROR] Connection in use: ('0.0.0.0', 8000)
2021-04-22T07:44:16.193252490Z [2021-04-22 07:44:16 +0000] [81] [ERROR] Retrying in 1 second.
2021-04-22T07:44:17.198116636Z [2021-04-22 07:44:17 +0000] [81] [ERROR] Connection in use: ('0.0.0.0', 8000)
2021-04-22T07:44:17.198923561Z [2021-04-22 07:44:17 +0000] [81] [ERROR] Retrying in 1 second.
2021-04-22T07:44:18.202126554Z [2021-04-22 07:44:18 +0000] [81] [ERROR] Connection in use: ('0.0.0.0', 8000)
2021-04-22T07:44:18.202984981Z [2021-04-22 07:44:18 +0000] [81] [ERROR] Retrying in 1 second.
2021-04-22T07:44:19.205241244Z [2021-04-22 07:44:19 +0000] [81] [ERROR] Connection in use: ('0.0.0.0', 8000)
2021-04-22T07:44:19.206164874Z [2021-04-22 07:44:19 +0000] [81] [ERROR] Retrying in 1 second.
2021-04-22T07:44:20.212049651Z [2021-04-22 07:44:20 +0000] [81] [ERROR] Connection in use: ('0.0.0.0', 8000)
2021-04-22T07:44:20.212092253Z [2021-04-22 07:44:20 +0000] [81] [ERROR] Retrying in 1 second.
2021-04-22T07:44:21.224597387Z [2021-04-22 07:44:21 +0000] [81] [ERROR] Can't connect to ('0.0.0.0', 8000)
2021-04-22T07:44:21.290608046Z [2021-04-22 07:44:21 +0000] [80] [INFO] Worker exiting (pid: 80)
2021-04-22T07:44:21.738321231Z [2021-04-22 07:44:21 +0000] [83] [INFO] Booting worker with pid: 83
2021-04-22T07:44:24.918365696Z  * Serving Flask app "app" (lazy loading)
2021-04-22T07:44:24.919426527Z  * Environment: production
2021-04-22T07:44:24.927208058Z    WARNING: This is a development server. Do not use it in a production deployment.
2021-04-22T07:44:24.927297361Z    Use a production WSGI server instead.
2021-04-22T07:44:24.927308061Z  * Debug mode: on
2021-04-22T07:44:24.946942144Z  * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
2021-04-22T07:44:24.948477689Z  * Restarting with stat
2021-04-22T07:44:25.709049858Z [2021-04-22 07:44:25 +0000] [84] [INFO] Starting gunicorn 20.0.4
2021-04-22T07:44:25.710487501Z [2021-04-22 07:44:25 +0000] [84] [ERROR] Connection in use: ('0.0.0.0', 8000)
2021-04-22T07:44:25.710858112Z [2021-04-22 07:44:25 +0000] [84] [ERROR] Retrying in 1 second.
2021-04-22T07:44:26.714606897Z [2021-04-22 07:44:26 +0000] [84] [ERROR] Connection in use: ('0.0.0.0', 8000)
2021-04-22T07:44:26.715566625Z [2021-04-22 07:44:26 +0000] [84] [ERROR] Retrying in 1 second.
2021-04-22T07:44:27.720325541Z [2021-04-22 07:44:27 +0000] [84] [ERROR] Connection in use: ('0.0.0.0', 8000)
2021-04-22T07:44:27.721384572Z [2021-04-22 07:44:27 +0000] [84] [ERROR] Retrying in 1 second.
2021-04-22T07:44:28.723318203Z [2021-04-22 07:44:28 +0000] [84] [ERROR] Connection in use: ('0.0.0.0', 8000)
2021-04-22T07:44:28.724247231Z [2021-04-22 07:44:28 +0000] [84] [ERROR] Retrying in 1 second.
2021-04-22T07:44:29.729845005Z [2021-04-22 07:44:29 +0000] [84] [ERROR] Connection in use: ('0.0.0.0', 8000)
2021-04-22T07:44:29.729874606Z [2021-04-22 07:44:29 +0000] [84] [ERROR] Retrying in 1 second.
2021-04-22T07:44:30.737813594Z [2021-04-22 07:44:30 +0000] [84] [ERROR] Can't connect to ('0.0.0.0', 8000)
2021-04-22T07:44:30.856350361Z [2021-04-22 07:44:30 +0000] [83] [INFO] Worker exiting (pid: 83)
2021-04-22T07:44:31.803916981Z [2021-04-22 07:44:31 +0000] [86] [INFO] Booting worker with pid: 86
2021-04-22T07:44:35.656121474Z  * Serving Flask app "app" (lazy loading)
2021-04-22T07:44:35.657028702Z  * Environment: production
2021-04-22T07:44:35.657041702Z    WARNING: This is a development server. Do not use it in a production deployment.
2021-04-22T07:44:35.657838227Z    Use a production WSGI server instead.
2021-04-22T07:44:35.664767041Z  * Debug mode: on
2021-04-22T07:44:35.694054348Z  * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
2021-04-22T07:44:35.695509793Z  * Restarting with stat
2021-04-22T07:44:36.453792055Z [2021-04-22 07:44:36 +0000] [87] [INFO] Starting gunicorn 20.0.4
2021-04-22T07:44:36.461107781Z [2021-04-22 07:44:36 +0000] [87] [ERROR] Connection in use: ('0.0.0.0', 8000)
2021-04-22T07:44:36.461484393Z [2021-04-22 07:44:36 +0000] [87] [ERROR] Retrying in 1 second.
2021-04-22T07:44:37.468035639Z [2021-04-22 07:44:37 +0000] [87] [ERROR] Connection in use: ('0.0.0.0', 8000)
2021-04-22T07:44:37.469176575Z [2021-04-22 07:44:37 +0000] [87] [ERROR] Retrying in 1 second.
2021-04-22T07:44:38.474207365Z [2021-04-22 07:44:38 +0000] [87] [ERROR] Connection in use: ('0.0.0.0', 8000)
2021-04-22T07:44:38.475101293Z [2021-04-22 07:44:38 +0000] [87] [ERROR] Retrying in 1 second.
2021-04-22T07:44:39.480162485Z [2021-04-22 07:44:39 +0000] [87] [ERROR] Connection in use: ('0.0.0.0', 8000)
2021-04-22T07:44:39.481085413Z [2021-04-22 07:44:39 +0000] [87] [ERROR] Retrying in 1 second.
2021-04-22T07:44:40.486103803Z [2021-04-22 07:44:40 +0000] [87] [ERROR] Connection in use: ('0.0.0.0', 8000)
2021-04-22T07:44:40.487006832Z [2021-04-22 07:44:40 +0000] [87] [ERROR] Retrying in 1 second.
2021-04-22T07:44:41.492332131Z [2021-04-22 07:44:41 +0000] [87] [ERROR] Can't connect to ('0.0.0.0', 8000)
2021-04-22T07:44:41.557393470Z [2021-04-22 07:44:41 +0000] [86] [INFO] Worker exiting (pid: 86)
2021-04-22T07:44:42.033036773Z [2021-04-22 07:44:42 +0000] [89] [INFO] Booting worker with pid: 89
2021-04-22T07:44:45.214064517Z  * Serving Flask app "app" (lazy loading)
2021-04-22T07:44:45.214945645Z  * Environment: production
2021-04-22T07:44:45.215503462Z    WARNING: This is a development server. Do not use it in a production deployment.
2021-04-22T07:44:45.221783155Z    Use a production WSGI server instead.
2021-04-22T07:44:45.221798256Z  * Debug mode: on
2021-04-22T07:44:45.243216415Z  * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
2021-04-22T07:44:45.251290463Z  * Restarting with stat
2021-04-22T07:44:46.019374903Z [2021-04-22 07:44:46 +0000] [90] [INFO] Starting gunicorn 20.0.4
2021-04-22T07:44:46.026407319Z [2021-04-22 07:44:46 +0000] [90] [ERROR] Connection in use: ('0.0.0.0', 8000)
2021-04-22T07:44:46.026422620Z [2021-04-22 07:44:46 +0000] [90] [ERROR] Retrying in 1 second.
2021-04-22T07:44:47.031561655Z [2021-04-22 07:44:47 +0000] [90] [ERROR] Connection in use: ('0.0.0.0', 8000)
2021-04-22T07:44:47.032497484Z [2021-04-22 07:44:47 +0000] [90] [ERROR] Retrying in 1 second.
2021-04-22T07:44:48.035110541Z [2021-04-22 07:44:48 +0000] [90] [ERROR] Connection in use: ('0.0.0.0', 8000)
2021-04-22T07:44:48.035988968Z [2021-04-22 07:44:48 +0000] [90] [ERROR] Retrying in 1 second.
2021-04-22T07:44:49.040344579Z [2021-04-22 07:44:49 +0000] [90] [ERROR] Connection in use: ('0.0.0.0', 8000)
2021-04-22T07:44:49.041809624Z [2021-04-22 07:44:49 +0000] [90] [ERROR] Retrying in 1 second.
2021-04-22T07:44:50.042151212Z [2021-04-22 07:44:50 +0000] [90] [ERROR] Connection in use: ('0.0.0.0', 8000)
2021-04-22T07:44:50.045851326Z [2021-04-22 07:44:50 +0000] [90] [ERROR] Retrying in 1 second.
2021-04-22T07:44:51.064407674Z [2021-04-22 07:44:51 +0000] [90] [ERROR] Can't connect to ('0.0.0.0', 8000)
2021-04-22T07:44:51.114340611Z [2021-04-22 07:44:51 +0000] [89] [INFO] Worker exiting (pid: 89)
2021-04-22T07:44:51.546058198Z [2021-04-22 07:44:51 +0000] [92] [INFO] Booting worker with pid: 92
2021-04-22T07:44:54.704747927Z  * Serving Flask app "app" (lazy loading)
2021-04-22T07:44:54.764574498Z  * Environment: production
2021-04-22T07:44:54.764595098Z    WARNING: This is a development server. Do not use it in a production deployment.
2021-04-22T07:44:54.764601098Z    Use a production WSGI server instead.
2021-04-22T07:44:54.764604898Z  * Debug mode: on
2021-04-22T07:44:54.764659100Z  * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
2021-04-22T07:44:54.764668000Z  * Restarting with stat
2021-04-22T07:44:55.487360391Z [2021-04-22 07:44:55 +0000] [93] [INFO] Starting gunicorn 20.0.4
2021-04-22T07:44:55.494123403Z [2021-04-22 07:44:55 +0000] [93] [ERROR] Connection in use: ('0.0.0.0', 8000)
2021-04-22T07:44:55.495235437Z [2021-04-22 07:44:55 +0000] [93] [ERROR] Retrying in 1 second.

Searched a while and tried the fuser or kill commands I found online, but fuser is not recognized on Web app, and kill command just doesn't work with this error message:

/home# kill `lsof -i :8000`
-bash: lsof: command not found
kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l

Update 2

using the below command:

gunicorn --bind=0.0.0.0 --timeout 600 application:app

and here is the output

ut 600  application:app18b:/tmp/8d90556500a845d# gunicorn --bind=0.0.0.0 --timeou
[2021-04-23 07:30:39 +0000] [93] [INFO] Starting gunicorn 20.0.4
[2021-04-23 07:30:39 +0000] [93] [ERROR] Connection in use: ('0.0.0.0', 8000)
[2021-04-23 07:30:39 +0000] [93] [ERROR] Retrying in 1 second.
[2021-04-23 07:30:40 +0000] [93] [ERROR] Connection in use: ('0.0.0.0', 8000)
[2021-04-23 07:30:40 +0000] [93] [ERROR] Retrying in 1 second.
[2021-04-23 07:30:41 +0000] [93] [ERROR] Connection in use: ('0.0.0.0', 8000)
[2021-04-23 07:30:41 +0000] [93] [ERROR] Retrying in 1 second.
[2021-04-23 07:30:42 +0000] [93] [ERROR] Connection in use: ('0.0.0.0', 8000)
[2021-04-23 07:30:42 +0000] [93] [ERROR] Retrying in 1 second.
[2021-04-23 07:30:43 +0000] [93] [ERROR] Connection in use: ('0.0.0.0', 8000)
[2021-04-23 07:30:43 +0000] [93] [ERROR] Retrying in 1 second.
[2021-04-23 07:30:44 +0000] [93] [ERROR] Can't connect to ('0.0.0.0', 8000)

Using Azure app SSH under the Advanced tool, it's such a pain. My ssh console got disconnected every often and sometimes it amount the correct folder for me , then I can see my python code files. Other times it shows me a strange folder which has no my code at all.... e.g.

root@ece8fefe856f:/home# ls
37391ef6fffba0c96cda20c7  ASP.NET  LogFiles  site
Franva
  • 6,565
  • 23
  • 79
  • 144
  • Have your tried linode? Allows you to buy a Linux server. Also, if you search this up on youtube, lots of people use linode to deploy flask applications – Zachary Apr 17 '21 at 07:24
  • Also found out tech with Tim has a sponsorship with linode where you can get a 100$ credit https://www.linode.com/lp/youtube-viewers/?ifso=techwithtim – Zachary Apr 17 '21 at 07:28
  • does it work locally? – Beppe C Apr 17 '21 at 19:47
  • If my reply is helpful, please accept it as answer(click on the mark option beside the reply to toggle it from greyed out to fill in.), see https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – Jason Pan Apr 21 '21 at 04:06
  • @BeppeC yep. it works fine locally. there is no reason to deploy a not working project. – Franva Apr 21 '21 at 13:49
  • Sure, just checking before suggesting to use Heroku Docker Registry. You can build the image locally then push it to Heroku. You control the build and just deploy the final image. – Beppe C Apr 21 '21 at 14:12
  • thanks @BeppeC is Heroku Docker a free service to use? I was trying to install the scikit-fmm on Heroku but got no luck. – Franva Apr 21 '21 at 14:16
  • 1
    When you use a free Dyno you can deploy with git or Docker Registry, so you can use if for free. Build the Docker image locally installing the dependencies you need and then push the image to Heroku. – Beppe C Apr 21 '21 at 14:19

4 Answers4

1

UPDATE

After my test, because the latest version of scikit-fmm is not compatible with azure web app, I used the scikit-fmm==2021.1.21 version. It works for me.

enter image description here

Thanks for Glenn's reminder, you can use below cmd in webssh.

apt-get update
apt-get install g++
pip install scikit-fmm==2021.1.21

PREVIOUS

Without knowing which packages you need to install in your requirements.txt.

I personally recommend that you create azure web app with container (linux), so that you can manually execute the script to install the packages used by the project after deploying the project.

I have not deployed a flask application under Linux. If you can use windows, I recommend using windows webapp.

You can refer my answer in below post.

How to deploy a Flask+React application to Azure Web Service

Jason Pan
  • 15,263
  • 1
  • 14
  • 29
  • hi @jsaonPan, yes I created a linux webapp and tried to install that scikit-fmm from the console on Azure, but it failed with same error. – Franva Apr 21 '21 at 13:50
  • @Franva After testing, there is no need to use docker to redeploy your web project for the time being. Using `scikit-fmm==2021.1.21` will solve your problem. – Jason Pan Apr 22 '21 at 03:50
  • @Franva If my reply is helpful, please accept it as answer(click on the mark option beside the reply to toggle it from greyed out to fill in.), see https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – Jason Pan Apr 22 '21 at 03:50
  • hi @jasonPan, thanks for your update. Yes, I tried to update the linux first and then installed g++, then I am able to installed the latest scikit-fmm 2021.2.2. So excited~! I'm deploying it, will come back to update you. cheers – Franva Apr 22 '21 at 05:44
  • @Franva Glad you received your reply. I am looking forward to your deployment results. ^-^ – Jason Pan Apr 22 '21 at 06:17
  • hi @JasonPan the deployment is successful, but the app doesn't work. I have updated my question, please see my update 1. thanks – Franva Apr 22 '21 at 07:58
  • @Franva https://stackoverflow.com/questions/59648128/how-to-setup-the-startup-command-for-a-flask-azure-web-app – Jason Pan Apr 22 '21 at 08:01
  • @Franva You need add startup command on portal. – Jason Pan Apr 22 '21 at 08:01
  • hi @JasonPan, I have tried the startup command on portal, unfortunately, it failed with the same error. Also had a look at your another pose, it was using Python 2.7 which is quite old version. I'm using 3.8. Please see my Update 2 – Franva Apr 23 '21 at 07:37
  • @Franva There is only so much I can do. If you have a clear mistake, I can give you ideas for solving the problem. I suggest you still raise a support ticket on portal. – Jason Pan Apr 23 '21 at 07:39
  • hi Jason, I added a bit more info there. I will add my code later today and hopefully you could give it a try from your side to see whether it works on Azure Webapp. thanks for your help. – Franva Apr 23 '21 at 07:44
  • 1
    @Franva If possible, you can create a sample project from me without sencitive info, I will try to fix it next week. – Jason Pan Apr 23 '21 at 07:46
  • Hi Jason, I highly appreciate your willingness to help. Please find my repo here: https://github.com/franva/flaskapi – Franva Apr 24 '21 at 12:19
  • @Franva https://stackoverflow.com/questions/66251679/deploy-fastapi-and-uvicorn-on-azure-app-service/66346091#66346091 – Jason Pan Apr 26 '21 at 05:29
  • hi @JasonPan, have you tried my code which I provided above in my repository? I have read the link you sent in the last comment. It was using FastAPI not FlaskAPI which was what I was using. Never mind, I changed my project to use FastAPI, still no luck. Are you able to set up the project on Azure successfully? – Franva Apr 26 '21 at 09:35
  • @Franva Have try my sample code? https://github.com/Jason446620/fastapi-uvicon – Jason Pan Apr 26 '21 at 09:49
  • @Franva It may just be that the startup command is different. You need to query the application log to locate the error message. – Jason Pan Apr 26 '21 at 09:50
  • hi Jason, I finally figured out which part is missed out. Thanks for your help. Looking at the application log helped :) – Franva Apr 26 '21 at 13:07
  • Could you accept my solution as answer, because I found the lastest version of scikit-fmm can’t use in azure web app. – Jason Pan Apr 26 '21 at 13:10
1

The 127 status code for the g++ command suggests that g++ is not installed on the platform where you tried that install. Do you get the same error on all the platforms?

Glenn
  • 7,262
  • 1
  • 17
  • 23
1

You can choose to deploy via the Heroku Docker Registry building the image locally and (after testing) pushing it to Heroku. The advantage is that you control the build (not Heroku).

Define the Dockerfile of the Python app (example below)

FROM python:3.9-slim

COPY app/ /app

EXPOSE 5000

WORKDIR /app
RUN pip install -r requirements.txt

ENTRYPOINT ["python"]
CMD ["app.py"]

Build the image locally (using the naming conventions required by Heroky i.e. appname)

# build image
docker build -t registry.heroku.com/appname/web .

The image should contain your app and all dependencies/models you need. You can test this locally with docker run.

Push and release the image:

# login into Docker Registry (only once)
heroku container:login
# push
docker push registry.heroku.com/appname/web
# release
heroku container:release web -a appname
Beppe C
  • 11,256
  • 2
  • 19
  • 41
  • 1
    thanks man. I'm trying Azure atm. But always like to learn how to use Docker image. Once I made it work on Azure, I will come back to the Docker image and update you. Cheers! – Franva Apr 22 '21 at 05:45
0

I finally figured out how to deploy Python API project on Azure using Web App.

Btw, I changed to use FastAPI rather than Flask, as FastAPI is newer and packed with more features.

The very important tip is to look into the log.

I actually already know it, but I could not find the log.

I then found a log stream which is constantly streaming logs to this page:

https://{your-web-app-name}.scm.azurewebsites.net/api/logstream

From here, I was able to see that many issues I had were because of missing packages.

Also under Settings --> Configuration --> General settings, put the below code into Startup Command:

gunicorn -w 4 -k uvicorn.workers.UvicornWorker main:app --timeout 1200

One more place to point out: I also looked at the Log under Deployment Center. Don't be misled by its notification. I saw deployed successfully, I thought everything was correct, but it's not.

You could still have missing packages when the deployment was successful.

So do look into the Log Stream.

Franva
  • 6,565
  • 23
  • 79
  • 144