Context
I have a flask application that runs locally. It is just a GUI for another program. I made it a desktop app by using pywebview and everything works fine when I run it using my local Python interpreter.
Minimal representation of the project structure:
src
┣ flask_application
┃ ┣ configuration
┃ ┃ ┣ with_dynaconf.py
┃ ┃ ┗ __init__.py
┃ ┣ app.py
┃ ┗ __init__.py
┣ desktop.py
┗ __init__.py
Starting point of the project is desktop.py
:
import webview
from flask_application.app import create_app
server = create_app()
webview.create_window('my program', server)
webview.start()
app.py
content is:
import flask
from .configuration import with_dynaconf
def create_app():
app = flask.Flask(__name__)
# Init the extensions and configurations with dynaconf
with_dynaconf.init_app(app)
return app
with_dynaconf.py
content is:
from dynaconf import FlaskDynaconf
def init_app(app):
FlaskDynaconf(app)
The error
I'm trying to make the project an executable file using pyinstaller.
This is the pyinstaller command I'm running:
pyinstaller --noconfirm --onedir --windowed --add-data "src/flask_application;flask_application/" --hidden-import "flask" --hidden-import "dynaconf" "src/desktop.py"
When I run the executable I get the following error message:
Traceback (most recent call last):
File "src\desktop.py", line 5, in <module>
File "exe_root\flask_application\app.py", line 12, in create_app
with_dynaconf.init_app(app)
File "exe_root\flask_application\configuration\with_dynaconf.py", line 5, in init_app
FlaskDynaconf(app)
File "dynaconf\contrib\flask_dynaconf.py", line 109, in __init__
File "dynaconf\contrib\flask_dynaconf.py", line 118, in init_app
File "dynaconf\contrib\flask_dynaconf.py", line 132, in make_config
File "dynaconf\contrib\flask_dynaconf.py", line 150, in __init__
File "dynaconf\base.py", line 121, in __getattr__
File "dynaconf\base.py", line 180, in _setup
File "dynaconf\base.py", line 262, in __init__
File "dynaconf\base.py", line 1149, in execute_loaders
File "dynaconf\loaders\__init__.py", line 47, in default_loader
File "dynaconf\default_settings.py", line 55, in start_dotenv
File "dynaconf\base.py", line 1315, in find_file
File "dynaconf\utils\files.py", line 67, in find_file
File "dynaconf\utils\files.py", line 14, in _walk_to_root
OSError: Starting path not found
What I've tried
I already tried to debug the application using my local Python interpreter, but when it gets on
File "dynaconf\base.py", line 120, in __getattr__
the if statement is false and it does not runFile "dynaconf\base.py", line 121, in __getattr__
. This is different from when the exe file is run, which executesFile "dynaconf\base.py", line 121, in __getattr__
and beyond.I also tried to remove the
with_dynaconf.init_app(app)
line fromapp.py
. It causes the rest of the code to run fine but without all the extensions and configurations.
Final
At this point, I have no idea what the problem is. Any help is appreciated. If you need more information just ask and I'll happily provide it.