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?
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.
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 :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With