Is there an easy way to distribute a Flask server as an executable? Is there an easy way to distribute a Flask server as an executable? flask flask

Is there an easy way to distribute a Flask server as an executable?


You can use Anthony Gordon McMillan’s Pyinstaller or Tuininga’s cx_Freeze

Quoting the PyInstaller website:

Features

Packaging of Python programs into standard executables, that work on computers without Python installed.

Multiplatform: works under

  • Windows (32-bit and 64-bit),
  • Linux (32-bit and 64-bit),
  • Mac OS X (32-bit only, 64-bit in git, see Features/MacOsCompatibility) and experimentally Solaris and AIX (in git).

Multiversion: works under any version of Python from 2.2 up to 2.7.


My suggestion would be to create a thin service wrapper around your code. This will allow the server to run independently of your main codebase - also allowing the user to shut down the server directly (simply right clicking the service icon and selecting "Exit").

This SO answer should help you get started.

After reading your updated question, I think something like mongoose might be more suited to your task. It is an embeddable web server that is FLOSS and has python bindings. Flask might be overkill.


Not easily. On Windows, you'd have to include Python itself. Mac and Linux usually have Python installed, but you can't be sure of what version so it's often easier to bundle your specific Python for them as well. Then you'd have to include all the dependencies that you want to run with in your package or be able to install them with pip, easy_install, etc.

You can use py2app and py2exe. This won't be cross-platform as you'll still need to make a different version for each target OS. The only way to make it cross-platform is to bundle all versions and have some cross-platform code execute the appropriate version for that platform.

If you need databases like MySQL or even SQLite things get more complicated as you'll have to include those too.