我一直在研究一个需要使用pyinstaller加载数据文件(PNG文件和锅文件)的应用程序,并且我一直在跟踪临时文件夹的文件,数据文件不会添加到出于某种原因,临时文件夹。我做了一个小模块,以保持其作为后续目录的轨迹:使用pyinstaller2.0加载数据文件
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)
我用以下两个命令建造的exe
pyinstaller.py --onefile filename.py
pyinstaller.py --onefile filename.spec
并且数据文件未加载到目录。我也尝试运行一个日志,显示这个目录中的所有文件,数据文件没有显示出来。下面是它的截图:
http://imgur.com/delete/qIff0zZT2Y4ZdKT
我使用python 2.7和2.0 pyinstaller。任何人都知道问题是什么?提前致谢!
我不认为你可以做--onefile和其他任何东西--onefile; P ...你将不得不手动将资源放在同一个地方,并可能创建一个zip或其他东西(我可能是错的.. 。) –