前提・実現したいこと
Kivyでjpgを表示するアプリをつくり、PyinstallerでEXE化しました。
しかし、画像ファイルが読み込めず、以下のエラーメッセージが発生しました。
EXE化の手順
>python -m PyInstaller --name image image.py --onefile
>python -m PyInstaller image.spec
発生している問題・エラーメッセージ
[ERROR ] [Image ] Error loading texture ./sample1.jpg
[INFO ] [Base ] Start application main loop
[INFO ] [GL ] NPOT texture support is available
[WARNING] [Image ] Unable to load image <C:\Users\EES\De
uichiro\Other\Kivy\Image_EXE\dist\sample2.jpg>
[ERROR ] [Image ] Error loading texture ./sample2.jpg
該当のソースコード
image.py
#-*- coding: utf-8 -*- """ Author: Yuichiro Atomの場合、Alt + Rで実行可能 """ import os os.environ["KIVY_IMAGE"] = "sdl2" import kivy import sys from kivy.config import Config Config.set('graphics', 'width', '640') Config.set('graphics', 'height', '480') from PyQt5.QtGui import QIcon from PyQt5.QtWidgets import QApplication, QWidget from kivy.app import App from kivy.uix.widget import Widget from kivy.properties import StringProperty from kivy.core.text import LabelBase, DEFAULT_FONT from kivy.resources import resource_add_path # デフォルトに使用するフォントを変更する LabelBase.register(DEFAULT_FONT, 'mplus-2c-regular.ttf') #日本語が使用できるように日本語フォントを指定する class ImageWidget(Widget): source = StringProperty('./sample1.jpg') #source = StringProperty(None) def __init__(self, **kwargs): super(ImageWidget, self).__init__(**kwargs) pass def buttonClicked(self): self.source= './sample1.jpg' class ImageApp(App): def __init__(self, **kwargs): super(ImageApp, self).__init__(**kwargs) self.title = str(os.getcwd()) if __name__ == '__main__': ImageApp().run()
image.kv
ImageWidget: <ImageWidget>: BoxLayout: orientation: 'vertical' size: root.size Image: source: root.source BoxLayout: size_hint_y: 0.3 padding: 20,30,20, 10 Button: id: button1 text: "sample1" font_size: 30 on_press: root.buttonClicked()
image.spec
# -*- mode: python -*- block_cipher = None a = Analysis(['image.py'], pathex=['C:\Users\EES\Desktop\SourceTree\Yuichiro\Other\Kivy\Image_EXE\dist'], binaries=[], datas=['C:\Users\EES\Desktop\SourceTree\Yuichiro\Other\Kivy\Image_EXE\dist\sample1.jpg'], hiddenimports=[], hookspath=[], runtime_hooks=[], excludes=[], win_no_prefer_redirects=False, win_private_assemblies=False, cipher=block_cipher, noarchive=False) pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) exe = EXE(pyz, a.scripts, a.binaries, a.zipfiles, a.datas, [], name='image', debug=False, bootloader_ignore_signals=False, strip=False, upx=True, runtime_tmpdir=None, console=True )
よろしくお願いいたします。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。