Skip to content

pyinstaller executable cannot find the needle images #3

Description

@geidien

When creating a --onefile executable for windows with pyinstaller using speedmeter. The needles on the meters bug out due to not being able to find the needle.png. This line in particular to get an idea of what I mean.

Also, I am no expert so please forgive me if I am not very clear.

Problem:
module >> init.py
_image_dir = os.path.join(os.path.dirname(file), 'images')

My Current work around Solution:
Add the following and comment out the following in init.py

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)

_image_dir = os.path.join(resource_path(''), 'images')
#_image_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'images')

Add the following to the pyinstaller .spec file. Of course change the location below to your directory
a.datas += [('images\needle.png','\location\to\kivy_garden\speedmeter\images\needle.png','DATA')]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions