10

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

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

The build works fine. But, if I try to do something like:

os.popen('sometool.exe'), the error is that was not found.

So, how can I do that?

Ethan Field
  • 4,646
  • 3
  • 22
  • 43
  • @JakubBláha I don't understand the ```.ico``` part - that just throws an error. The semicolon is for Windows and then it compiles properly (for me on Windows), however, just like the OP, I am unable to call ```sometool.exe``` in my script. – Y Davis Jun 18 '18 at 16:11
  • 1
    I don't really know, what I typed there :D – Jakub Bláha Jun 18 '18 at 17:18

3 Answers3

9

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.

Feng Liu
  • 954
  • 13
  • 22
4

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 :)

Jakub Bláha
  • 1,491
  • 5
  • 22
  • 43
1

For windows, you should use ; instead of : before the binary file path. like this :

pyinstaller  -F  --add-binary="sometool.exe;."  myapp.py
Simon Lau
  • 61
  • 1
  • 5