I have an app which embeds gunicorn and I can run with the classic
python myapp.py
However If I try to compile the app to be distributable with pyinstaller (http://www.pyinstaller.org/) and run it with:
./dist/myapp/myapp
I get the following error:
Error: class uri 'simple' invalid or not found:
[Traceback (most recent call last):
File "/home/mattions/Dev/guniconr_app/build/myapp/out00-PYZ.pyz/gunicorn.util", line 125, in load_class
File "/home/mattions/Dev/guniconr_app/build/myapp/out00-PYZ.pyz/pkg_resources", line 343, in load_entry_point
File "/home/mattions/Dev/guniconr_app/build/myapp/out00-PYZ.pyz/pkg_resources", line 336, in get_distribution
File "/home/mattions/Dev/guniconr_app/build/myapp/out00-PYZ.pyz/pkg_resources", line 215, in get_provider
File "/home/mattions/Dev/guniconr_app/build/myapp/out00-PYZ.pyz/pkg_resources", line 696, in require
File "/home/mattions/Dev/guniconr_app/build/myapp/out00-PYZ.pyz/pkg_resources", line 594, in resolve
DistributionNotFound: gunicorn
]
This is the example app that I have used: https://gist.github.com/mattions/8026970
This code works:
from gunicorn.app.base import Application, Config
import gunicorn
from gunicorn import glogging
from gunicorn.workers import sync
class GUnicornFlaskApplication(Application):
def __init__(self, app):
self.usage, self.callable, self.prog, self.app = None, None, None, app
def run(self, **options):
self.cfg = Config()
[self.cfg.set(key, value) for key, value in options.items()]
return Application.run(self)
load = lambda self:self.app
def app(environ, start_response):
data = "Hello, World!\n"
start_response("200 OK", [
("Content-Type", "text/plain"),
("Content-Length", str(len(data)))
])
return iter(data)
if __name__ == "__main__":
gunicorn_app = GUnicornFlaskApplication(app)
gunicorn_app.run(
worker_class="gunicorn.workers.sync.SyncWorker",
)
Some sub modules are not imported. See:
Most helpful comment
This code works:
Some sub modules are not imported. See:
http://www.pyinstaller.org/wiki/FAQ#IfThingsGoWrong