Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

serving a gunicorn app with PyInstaller #669

Closed
mattions opened this issue Dec 18, 2013 · 1 comment
Closed

serving a gunicorn app with PyInstaller #669

mattions opened this issue Dec 18, 2013 · 1 comment

Comments

@mattions
Copy link

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

@benoitc
Copy link
Owner

benoitc commented Dec 26, 2013

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:

http://www.pyinstaller.org/wiki/FAQ#IfThingsGoWrong

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants