簡體   English   中英

如何使用pyinstaller在exe文件的同一目錄中添加二進制數據文件?

[英]How to add a binary data file in the same directory as of exe using pyinstaller?

我有一個二進制文本文件,我想嵌入--onefile使用pyinstaller。 文本文件應與程序位於同一目錄中。 我使用了pyinstaller --onefile --add-binary a.txt;. A.py pyinstaller --onefile --add-binary a.txt;. A.py但它會產生錯誤PermissionError: [Errno 13] Permission denied: 'C:\\\\Users\\\\name\\\\Appdata\\Local\\pyinstaller\\bin000cache\\a.txt

嘗試以管理員身份運行,該文件不允許可執行文件訪問它....可選地,您可以從另一個py腳本中創建文件中的py腳本,並且讓此腳本只將二進制數據存儲為變量,它將是可靠的與文本文件大小相同,但我不會在編輯器中打開腳本

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

import script.py ,將var = / something用於多個行字符串,它會將所有內容讀入內存中,但是你可以del script.txtfile以后del script.txtfile

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM