sanic-org / sanic-openapi

Easily document your Sanic API with a UI
https://sanic-openapi.readthedocs.io/
MIT License
505 stars 107 forks source link

pyinstaller may cause problems with sanic and/or sanic-openapi #226

Closed chongtwo closed 2 years ago

chongtwo commented 3 years ago

(additional context added by sanic-openapi maintainer)

pyinstaller is a tool which bundles python and required libraries into an executable which should be able to be run regardless of the system having python installed

the issue below documents a potential problem with using this tool in combination with sanic-openapi

--

225

I've tried your suggestion but it didn't work. The code is as below:

# sanic-openapi-test.py
from sanic import Sanic
from sanic.response import json
from sanic_openapi import swagger_blueprint

app = Sanic(name="sanic_openapi_test")
app.blueprint(swagger_blueprint)

@app.route("/")
async def test(request):
    return json({"hello": "world"})

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=8000)

And I packaged the code by PyInstaller (pip install pyinstaller)

 pyinstaller sanic-openapi-test.py

Went into the dist directory that is made by the command above and ran the sanic_openapi_test.exe. The error appeared:

Traceback (most recent call last):
  File "sanic_openapi_test.py", line 6, in <module>
  File "sanic\app.py", line 421, in blueprint
  File "sanic\blueprints.py", line 234, in register
  File "sanic\app.py", line 345, in _apply_static
  File "sanic\mixins\routes.py", line 803, in _register_static
  File "sanic\mixins\routes.py", line 155, in decorator
  File "sanic\app.py", line 335, in _apply_route
  File "sanic\router.py", line 128, in add
  File "sanic_routing\router.py", line 170, in add
  File "sanic_routing\route.py", line 115, in add_handler
sanic_routing.exceptions.RouteExists: Route already registered: swagger/<__file_uri__> [GET]
[6444] Failed to execute script sanic_openapi_test

Hope you can help me solve this problem. Thanks!

artcg commented 3 years ago

Sorry to hear that! I unfortunately don't have access to any windows computers nor experience with pyinstaller so cant help you with this one then, but hope you can figure it out ...

chongtwo commented 3 years ago

It is not specific to windows. This happens on linux too.

ahopkins commented 3 years ago

Sorry to hear that! I unfortunately don't have access to any windows computers nor experience with pyinstaller so cant help you with this one then, but hope you can figure it out ...

I'll take a look in Sunday. Double check to make sure you have latest version of Sanic installed.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is incorrect, please respond with an update. Thank you for your contributions.