質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
PyInstaller

PyInstallerは、Pythonのスクリプトを一括でWindowsなどで動く実行可能ファイルに変換できるツールです。このツールを用いることで自作のPythonプログラムを別で使用する場合でもPythonをインストールする必要がありません。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Q&A

解決済

1回答

1477閲覧

pyinstallerでkivyをexe化したい

退会済みユーザー

退会済みユーザー

総合スコア0

PyInstaller

PyInstallerは、Pythonのスクリプトを一括でWindowsなどで動く実行可能ファイルに変換できるツールです。このツールを用いることで自作のPythonプログラムを別で使用する場合でもPythonをインストールする必要がありません。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

0グッド

0クリップ

投稿2019/10/11 09:12

前提・実現したいこと

pyinstallerを用いたkivyappのexe化を行いたいのですが、以下のようなエラーが発生します。
いろいろ調べたのですがわからないので助力お願いします。

発生している問題・エラーメッセージ

178 WARNING: stderr: File "cut.spec", line 3, in <module> from kivy.deps import sdl2, glew 178 WARNING: stderr: from kivy.deps import sdl2, glew ImportError: cannot import name 'sdl2' 179 WARNING: stderr: ImportError: cannot import name 'sdl2'

sdl2がインポートできないといわれる

該当のソースコード

main.py

# -*- coding: utf-8 -*- from random import random from kivy.app import App from kivy.config import Config import clip import cv2 import os f = open(os.devnull, 'w') sys.stderr = f sys.stdout = f sys.stdin = f # 起動時の解像度の設定 Config.set('graphics', 'width', '1024') Config.set('graphics', 'height', '768') # 16:9 Config.set('graphics', 'resizable', False) # ウインドウリサイズ禁止 from kivy.uix.widget import Widget from kivy.uix.button import Button from kivy.graphics import Color, Ellipse, Line from kivy.properties import ObjectProperty from kivy.uix.behaviors import ToggleButtonBehavior from kivy.uix.togglebutton import ToggleButton from kivy.utils import get_color_from_hex # 色の16進数表示を可能にする from kivy.core.window import Window class MyPaintWidget(Widget): #pass last_color = '' # 画面クリアを押された場合の最後の色 line_width = 3 # 線の太さ def on_touch_down(self, touch): if Widget.on_touch_down(self, touch): return color = (random(), 1, 1) with self.canvas: touch.ud['line'] = Line(points=(touch.x, touch.y), width=self.line_width) def set_line_width(self, line_width=3): self.line_width = line_width def on_touch_move(self, touch): if touch.ud: # スライダーを動かす際のエラーを解除するため touch.ud['line'].points += [touch.x, touch.y] def set_color(self, new_color): self.last_color = new_color self.canvas.add(Color(*new_color)) class MyCanvasWidget(Widget): def clear_canvas(self): MyPaintWidget.clear_canvas(self) class MyPaintApp(App): def __init__(self, **kwargs): super(MyPaintApp, self).__init__(**kwargs) self.title = '画像表示' def build(self): parent = Widget() self.painter = MyCanvasWidget() # 起動時の色の設定を行う self.painter.ids['paint_area'].set_color(get_color_from_hex('#000000')) #黒色を設定 return self.painter def clear_canvas(self): self.painter.ids['paint_area'].canvas.clear() self.painter.ids['paint_area'].set_color(self.painter.ids['paint_area'].last_color) def save_canvas(self): if not os.path.exists("\base"): os.makedirs("\base") filename_base = 'sample.png' img_path = Window.screenshot("base\" + filename_base) # スクリーンショットを保存する basename = os.path.basename(img_path) img = cv2.imread("base\" + basename) cv2.rectangle(img, (0, 0), (78, 39), (255, 255, 255), thickness=-1) img = img[0:637, 0:1024] clip.mask_and_alpha(img, clip.maskgenerate(img, basename), basename) class ColorButton(ToggleButton): def _do_press(self): if self.state == 'normal': ToggleButtonBehavior._do_press(self)# ボタンを押されてない場合は状態を変更する if __name__ == '__main__': if(get_color_from_hex == None): Window.clearcolor = (1, 1, 1, 1) else: Window.clearcolor = get_color_from_hex('#ffffff') # ウィンドウの色を白色に変更する MyPaintApp().run()

mypaint.kv

#:import hex_color kivy.utils.get_color_from_hex <ColorButton>: background_normal: 'color_button_normal.png' background_down: 'color_button_down.png' group: 'color' border: (5, 5, 5, 5) on_release: app.painter.ids['paint_area'].set_color(self.background_color) #on_release: app.painter.paint_id.set_color(self.background_color) # こ�?�方法でもset_corlorにアクセス可能 <MyCanvasWidget>: paint_id:paint_area id: canvas_area test:button1 Button: text: 'save' color: 1, 1, 1 , 1 font_size: 20 on_release: app.save_canvas() border: (2, 2, 2, 2) x: 0 top: root.top width: 80 height: 40 BoxLayout: orientation: 'vertical' height: root.height width: root.width MyPaintWidget: id: paint_area size_hint_y: 0.8 BoxLayout: orientation: 'horizontal' size_hint_y: 0.1 Label: size_hint_x: 0.1 text: 'Line width %s' % int(s1.value) if s1.value else 'Line width not set' color: 0,0,0,1 Slider: id: s1 size_hint_x: 0.9 value: 3 range: (1,100) step: 1 on_touch_down:app.painter.ids['paint_area'].set_line_width(self.value) BoxLayout: orientation: 'horizontal' size_hint_y: 0.1 clear_btn:button1 Button: id: button1 text: "Clear" ont_size: 30 on_release: app.clear_canvas() ColorButton: text: "white " color: 0, 0, 0 , 1 background_color: hex_color('#ffffff') ColorButton: text: "black " state: 'down' background_color: hex_color('#000000') ColorButton: text: "red " background_color: hex_color('#ff0000') ColorButton: text: "biue " background_color: hex_color('#0000ff') ColorButton: text: "green " background_color: hex_color('#008000') ColorButton: text: "orange" background_color: hex_color('#ff4500') ColorButton: text: "purple" background_color: hex_color('#800080')

clip.py

import numpy as np import cv2 import os #関数定義 def threshprocess(img, basename): #edges = cv2.Canny(img,100,101,None, 3, True) #cv2.imwrite("canny\" + basename,edges)#エッジ画像保存 #can_img = cv2.imread("canny\" + basename)#エッジ画像の読み込み #return can_img if not os.path.exists("\thresh"): os.makedirs("\thresh") ret, thresh = cv2.threshold(img, 127, 255, cv2.THRESH_BINARY_INV) cv2.imwrite("thresh\" + basename, thresh) img_thresh = cv2.imread("thresh\" + basename) return img_thresh def contourprocess(img): gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY) image, contours, hierarchy = cv2.findContours(gray, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) return contours def maskgenerate(img, basename): if not os.path.exists("mask\"): os.makedirs("mask\") back = np.zeros_like(img) cont = contourprocess(threshprocess(img,basename)) mask = cv2.drawContours(back, cont, -1, color=(255, 255, 255), thickness=-1) cv2.imwrite("mask\" + basename,mask) mask = cv2.imread("mask\" + basename,0) return mask def mask_and_alpha(base_img, mask_img, basename): if not os.path.exists("..\Resources\images\"): os.makedirs("..\Resources\images\") bgr_img = cv2.split(base_img) clip = cv2.merge(bgr_img + [mask_img]) cv2.imwrite("..\Resources\images\" + basename,clip) name = open("..\Resources\imageName.txt",'w',encoding='utf-8') name.write(basename) flag = open("..\Resources\imageLoad.txt",'w',encoding='utf-8') flag.write("1") name.close() flag.close() #関数定義

補足情報(FW/ツールのバージョンなど)

python 3.6.8
nuitka 0.6.5
https://qiita.com/kouki_tsuji/items/5848d82143fc135f1c62 ←のサイトを参考にしました

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問