[Python] Trouble adding data to pyinstaller [duplicate]

Discussão em 'Python' iniciado por Stack, Novembro 26, 2024.

  1. Stack

    Stack Membro Participativo

    I've been trying to add a folder and a .zip file to my .exe I create but either I'm not adding it right, or I can't figure out how to access it once it's added. Here is my Analysis part of my spec file:

    a = Analysis(
    ['main.py'],
    pathex=[],
    binaries=[],
    datas=[('files', '.'), ('minecraft_world.zip', '.')],
    hiddenimports=[],
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[],
    noarchive=False,
    optimize=0,
    )


    files is a folder, and minecraft_world.zip is the .zip file. Here is how I'm trying to access a file in files:

    subprocess.call("files\\Java.exe", shell=True)

    I make the .exe by running:

    python3 -m PyInstaller main.spec

    I would have used pyinstaller main.spec, but that returned a command not found error. python3 -m pyinstaller main.spec returns no such module pyinstaller

    I tried various directories like //, \, /, but they all said the system couldn't find the specified path. I also tried ./ but it said it couldn't find the command '.'

    UPDATE: I tried using os.path.join(sys._MEIPASS, "files", "Java.exe"), but it still said the system couldn't find the path specified. Here is the path it tried to navigate to:

    C:\Users\Admin\AppData\Local\Temp_MEI37642\files\Java.exe

    Continue reading...

Compartilhe esta Página