Skip to content
This repository has been archived by the owner on Feb 16, 2020. It is now read-only.

Internal server error after packaging with pyinstaller #9

Closed
weirdyang opened this issue Mar 7, 2018 · 13 comments
Closed

Internal server error after packaging with pyinstaller #9

weirdyang opened this issue Mar 7, 2018 · 13 comments

Comments

@weirdyang
Copy link

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!

@ELC
Copy link
Collaborator

ELC commented Mar 7, 2018

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

@weirdyang
Copy link
Author

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!

@ELC
Copy link
Collaborator

ELC commented Mar 8, 2018

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.

@weirdyang
Copy link
Author

weirdyang commented Mar 8, 2018 via email

@ELC
Copy link
Collaborator

ELC commented Mar 8, 2018

Just run pyinstaller without the w flag

@weirdyang
Copy link
Author

weirdyang commented Mar 8, 2018 via email

@ELC
Copy link
Collaborator

ELC commented Mar 8, 2018

So either you don't use the --add-data param in the pyinstaller or you have a problem with your templates

@weirdyang
Copy link
Author

weirdyang commented Mar 8, 2018 via email

@smoqadam
Copy link
Owner

smoqadam commented Mar 8, 2018

take a look at this it might be helpfull

@weirdyang
Copy link
Author

weirdyang commented Mar 12, 2018

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'

@ELC
Copy link
Collaborator

ELC commented Mar 12, 2018

Thanks for the comments, I will close the issue since it's solved

@ELC ELC closed this as completed Mar 12, 2018
ELC added a commit that referenced this issue Mar 13, 2018
@ELC
Copy link
Collaborator

ELC commented Mar 13, 2018

Readme updated

@weirdyang
Copy link
Author

btw this is the app I made with pyfladesk; https:/captmomo/drowzee
thanks again for your help :)

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

No branches or pull requests

3 participants