I would like to create an exe
with Pyinstaller
including a database (.db) and a picture (.png). I want everything into a single
You have to solve many issues to get this working. For example:
The first issue is solved by adjusting paths depending on execution mode.
def app_path(path):
frozen = 'not'
if getattr(sys, 'frozen', False):
# we are running in executable mode
frozen = 'ever so'
app_dir = sys._MEIPASS
else:
# we are running in a normal Python environment
app_dir = os.path.dirname(os.path.abspath(__file__))
return os.path.join(app_dir, path)
The second issue is efficiently including what you need. At first the obvious solution is to add each image and db manually, but i had lots of image. I turned to the spec file way using the wildcard operator (*) to add what i need in folder than adding folder/*
.
added_files = [
( './pics/*', 'pics' ),
( './db/*', 'db' ),
]
then in Analysis,
datas = added_files
A thorough answer is quite long. I've written this article to show in some minute details what i went through to solve the issue.