Internal server error after packaging with pyinstaller
weirdyang opened this issue · 13 comments
Hi,
The app works when I run it locally. However once I convert it to an exe using pyinstaller, I get an internal server error. Any ideas on how or where I can start troubleshooting this? First time using pyinstaller. THanks!
Could you please give some more information? Operative System and the output of the console. Check first if it works with one directory mode and the one file and in case of error show us the console
Hi,
I'm using windows 10, python3.6.
The error I get is 'internal server error', I thought it might be because of bad file paths, but I've tried the solution provided in this https://stackoverflow.com/questions/7674790/bundling-data-files-with-pyinstaller-onefile, and it works locally but not in an executable.
I just tried using one directory mode and it works!
Internal server error is the one shown in the main window, can you show us the error in the console? The trace of the error.
Just run pyinstaller without the w
flag
So either you don't use the --add-data param in the pyinstaller or you have a problem with your templates
Thanks. I tried it, but still no luck. I think it's because pyinstaller does not set the env variable as mentioned in this link: https://stackoverflow.com/questions/7674790/bundling-data-files-with-pyinstaller-onefile
I'll report back if I figure this out. thanks again for your help.
edit; Fixed it!!
Include this at the top, under imports
if getattr(sys, 'frozen', False):
template_folder =resource_path('templates')
static_folder = resource_path('static')
app = Flask(__name__, template_folder=template_folder, static_folder=static_folder)
else:
app = Flask(__name__)
Define this in a helper script:
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
return os.path.join(base_path, relative_path)
credit to Jonathon Reinhart
additional notes:
if building on a windows 10 system use:
pyinstaller -w -F --add-data "templates;templates" --add-data "static;static" app.py --path 'C:\Program Files (x86)\Windows Kits\10\Redist\ucrt\DLLs\x64'
Thanks for the comments, I will close the issue since it's solved
Readme updated
btw this is the app I made with pyfladesk; https://github.com/captmomo/drowzee
thanks again for your help :)