Ad

How To Add A Binary Data File In The Same Directory As Of Exe Using Pyinstaller?

- 1 answer

I have a binary text file which I want to embed in --onefile using pyinstaller. The text file should be in the same directory as of the program. I used pyinstaller --onefile --add-binary a.txt;. A.py but it creates an error PermissionError: [Errno 13] Permission denied: 'C:\\Users\\name\\Appdata\Local\pyinstaller\bin000cache\a.txt

Ad

Answer

try running as admin, the file doesnt let the executable access it.... optionally you can create a py script out of the file from another py script, and have this script just store the binary data as a variable, it would arugably be the same size as the text file, but i wouldnt open the script in an editor

a='txtfile="""'
with open('script.py' as 'wb') as v:
    with open('file.txt', 'rb') as f:
         a+=f.read()
    a+="""'
    v.write(a)

use the var = / something for multiple line strings once you import script.py it will read all that into memory,but u can del script.txtfile later

Ad
source: stackoverflow.com
Ad