私は、pyinstaller を使用してデータファイル (png ファイルと pot ファイル) をロードする必要があるアプリケーションに取り組んでおり、一時フォルダーのファイルを追跡してきましたが、何らかの理由でデータファイルが一時フォルダーに追加されません。次のようなディレクトリを追跡するための小さなモジュールを作成しました。
import os, sys
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
スペックファイルも変更しました:
a = Analysis(['mks_controller.py'],
pathex=['C:\\pyinstaller-2.0\\pyinstaller-2.0'],
hiddenimports=[],
hookspath=None)
a.datas += [('presentation.potx','C:\\pyinstaller-2.0\\pyinstaller-2.0\\bbpresentation.potx','DATA'),('splat.png','C:\\pyinstaller-2.0\\pyinstaller-2.0\\splat.png', 'DATA'),('logo.png','C:\\pyinstaller-2.0\\pyinstaller-2.0\\logo.png','DATA')]
pyz = PYZ(a.pure)
次の 2 つのコマンドを使用して exe をビルドしました。
pyinstaller.py --onefile filename.py
pyinstaller.py --onefile filename.spec
データファイルがディレクトリにロードされていません。また、このディレクトリにあるすべてのファイルを示すログを実行しようとしましたが、データファイルは表示されません。そのスクリーンショットを次に示します。
http://imgur.com/delete/qIff0zZT2Y4ZdKT
私はpython 2.7とpyinstaller 2.0を使用しています。問題が何であるか誰にも分かりますか?前もって感謝します!