how to use bundled program after pyinstaller --add-binary?

前端 未结 2 692
半阙折子戏
半阙折子戏 2021-02-09 23:22

I am trying to make an executable with pyinstaller, by issuing something like this:

pyinstaller -F --add-binary=\"sometool.exe:.\" myapp.py

The b

相关标签:
2条回答
  • 2021-02-09 23:51

    For Unix like machine

    pyinstaller --noconfirm --log-level=WARN \
        --onefile --nowindow \
        --add-data="README:." \
        --add-data="image1.png:img" \
        --add-binary="libfoo.so:lib" \
        --hidden-import=secret1 \
        --hidden-import=secret2 \
        --upx-dir=/usr/local/share/ \
        myscript.spec
    

    Or for Windows

    pyinstaller --noconfirm --log-level=WARN ^
        --onefile --nowindow ^
        --add-data="README;." ^
        --add-data="image1.png;img" ^
        --add-binary="libfoo.so;lib" ^
        --hidden-import=secret1 ^
        --hidden-import=secret2 ^
        --icon=..\MLNMFLCN.ICO ^
        myscript.spec
    

    Official Doc: https://pyinstaller.readthedocs.io/en/stable/usage.html

    I spent hours to figure out how to use --add-binary and finally got it working. Look at --add-binary="libcrypto.dll:lib", you must add :lib as postfix.

    0 讨论(0)
  • 2021-02-09 23:54

    Try using this according to this question:

    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)
    

    And than in your app:

    os.popen(resource_path('sometool.exe'))
    

    This should work. I use this everyday :)

    0 讨论(0)
提交回复
热议问题