Find answers from the community

Updated 4 months ago

Hey everyone I m trying to package this

At a glance
Hey everyone, I'm trying to package this library into an executable for the first time and I'm running into some relative pathing issues. It looks like the first thing the executable runs into is this line of code in __init__.py:
Plain Text
with open(Path(__file__).absolute().parents[0] / "VERSION") as _f:
    __version__ = _f.read().strip()

From what I understand, accessing files needs to be guarded with a check to see if it is running as a binary to correct the pathing with a piece of code like this:
Plain Text
def resolve_path(relative_path):
    """
    Determines if the app is running standalone (binary) or script
    and chooses current working directory or application directory
    then converts relative path to absolute path accordingly
    """
    if getattr(sys, "frozen", False):
        # If the 'frozen' flag is set, we are in bundled-app mode!
        absolute_path = os.path.abspath(os.path.join(sys._MEIPASS, relative_path))
    else:
        # Normal development mode. Use os.getcwd() or __file__ as appropriate in your case...
        absolute_path = os.path.abspath(os.path.join(os.getcwd(), relative_path))

    return absolute_path

Does anyone know if there is a way to get around this issue without patching the whole library? Any thoughts?
L
c
3 comments
any reason you are trying to compile an executable vs. a normal pip package install? I feel like executables aren't typical in a python workflow
(I have no idea how to fix that btw, just curious)
I'm hoping to package my app as a simple "pass off to anyone and run it" kind of deal that won't require the extra step of installing Python and requirements.
Add a reply
Sign up and join the conversation on Discord