I've made a Flask app in Python which I want to turn into an exe for distribution, for that I'm trying to use cx_freeze.
When I run the app from Python or Pycharm, it works perfectly, but after I bundle it up, every request just hangs (spins in chrome). I tried debugging it and ended up creating a new flask app with just one route and no other dependencies, and the same thing happens.
Here's the test app I made (testapp/app.py
):
from flask import Flask
# Create flask app
webapp = Flask(__name__)
@webapp.route('/')
def home():
print "home"
return 'hello there'
The setup.py
for it:
from setuptools import find_packages
from cx_Freeze import setup, Executable
setup(
name='testapp',
description='Test Flask App',
packages=find_packages(),
include_package_data=True,
zip_safe=False,
install_requires=[
'Flask',
'waitress',
],
options={
"build_exe": {
"packages": [
"flask",
"waitress",
"threading",
"os",
],
'include_msvcr': True,
}
},
executables=[
Executable(
"run.py",
icon="icon.ico",
)
]
)
And the run.py
which serves as my entry point
from testapp.app import webapp
import sys
import waitress
if __name__ == "__main__":
PORT = sys.argv[1] if len(sys.argv) > 1 else 8080
waitress.serve(webapp, port=PORT)
I've read a few other questions but it seems to always end up being a templating problem, but this app isn't using templates and neither is my real app.
When I run it normally I get the output below and the page says "hello" to me
Serving on http://Desktop-PC:8080
home
When I run it as an exe, I get the same console output but the page just hangs.
I'm using flask==0.12
and cx-Freeze==5.0.1
Any ideas on how I can debug this one?
Edit:
I've noticed that during build time, I get a lot of warnings about missing packages, but if I try add those packages to my setup.py
, cx_freeze throws errors about not being able to import them. But if I can't import them, and my app apparently needs them, shouldn't it fail to run normally?
List is a bit long, so it's in a gist
This ended up being a bug in cx_Freeze 5.0.1
which is now patched in cx_Freeze 5.0.2
.