0

前提

tkinterを使って画像クリックするアプリを作成しております。

pythonのスクリプトpyinstallerのコマンドでexe化すると画像クリックできなくなり、
下記のエラーが表示されます。

exe化する前に問題なくクリックできます。
またpythonのライブラリOpenCVをインストールしております。
エラーの原因の解決方法分かりますでしょうか。

実現したいこと

下記のスクリーンpyinstallerを使ってexe化後、
画像クリック操作させたいです。

アプリの操作
①画像取得>保存
②フォルダーで保存した画像を選択
③画像クリック

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

C:/Users/user1/Downloads/imageclick.PNG
Exception in Tkinter callback
Traceback (most recent call last):
  File "tkinter\__init__.py", line 1884, in __call__
  File "image_ver1.py", line 31, in click_image
  File "pyautogui\__init__.py", line 175, in wrapper
  File "pyautogui\__init__.py", line 213, in locateOnScreen
  File "pyscreeze\__init__.py", line 372, in locateOnScreen
  File "pyscreeze\__init__.py", line 352, in locate
  File "pyscreeze\__init__.py", line 252, in _locateAll_python
NotImplementedError: The confidence keyword argument is only available if OpenCV is installed.

pyinstallerをする時のコマンド

PS C:\Users\user1> pyinstaller "C:\Users\user1\Documents\python\image_ver1.py" --onefile
167 INFO: PyInstaller: 4.5.1
167 INFO: Python: 3.9.1
167 INFO: Platform: Windows-10-10.0.18362-SP0
171 INFO: wrote C:\Users\user1\image_ver1.spec
176 INFO: UPX is not available.
179 INFO: Extending PYTHONPATH with paths
['C:\\Users\\user1\\Documents\\python', 'C:\\Users\\user1']
523 INFO: checking Analysis
523 INFO: Building Analysis because Analysis-00.toc is non existent
524 INFO: Initializing module dependency graph...
529 INFO: Caching module graph hooks...
560 INFO: Analyzing base_library.zip ...
3026 INFO: Processing pre-find module path hook distutils from 'c:\\users\\user1\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-distutils.py'.
3029 INFO: distutils: retargeting to non-venv dir 'c:\\users\\user1\\appdata\\local\\programs\\python\\python39\\lib'
6740 INFO: Caching module dependency graph...
6936 INFO: running Analysis Analysis-00.toc
6951 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by c:\users\user1\appdata\local\programs\python\python39\python.exe
7080 WARNING: lib not found: api-ms-win-core-path-l1-1-0.dll dependency of c:\users\user1\appdata\local\programs\python\python39\python39.dll
7496 INFO: Analyzing C:\Users\user1\Documents\python\image_ver1.py
8495 INFO: Processing pre-find module path hook site from 'c:\\users\\user1\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-site.py'.
8497 INFO: site: retargeting to fake-dir 'c:\\users\\user1\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\fake-modules'
9901 INFO: Processing pre-safe import module hook setuptools.extern.six.moves from 'c:\\users\\user1\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module\\hook-setuptools.extern.six.moves.py'.
14235 INFO: Processing module hooks...
14235 INFO: Loading module hook 'hook-cv2.py' from 'c:\\users\\user1\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
14242 INFO: Loading module hook 'hook-pycparser.py' from 'c:\\users\\user1\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
14245 INFO: Loading module hook 'hook-difflib.py' from 'c:\\users\\user1\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
14249 INFO: Loading module hook 'hook-distutils.py' from 'c:\\users\\user1\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
14252 INFO: Loading module hook 'hook-distutils.util.py' from 'c:\\users\\user1\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
14255 INFO: Loading module hook 'hook-encodings.py' from 'c:\\users\\user1\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
14370 INFO: Loading module hook 'hook-heapq.py' from 'c:\\users\\user1\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
14373 INFO: Loading module hook 'hook-lib2to3.py' from 'c:\\users\\user1\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
14442 INFO: Loading module hook 'hook-multiprocessing.util.py' from 'c:\\users\\user1\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
14446 INFO: Loading module hook 'hook-numpy.py' from 'c:\\users\\user1\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
14545 INFO: Import to be excluded not found: 'f2py'
14553 INFO: Loading module hook 'hook-numpy._pytesttester.py' from 'c:\\users\\user1\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
14556 INFO: Loading module hook 'hook-packaging.py' from 'c:\\users\\user1\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
14558 INFO: Loading module hook 'hook-pickle.py' from 'c:\\users\\user1\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
14562 INFO: Loading module hook 'hook-PIL.Image.py' from 'c:\\users\\user1\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
14930 INFO: Loading module hook 'hook-PIL.ImageFilter.py' from 'c:\\users\\user1\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
14933 INFO: Loading module hook 'hook-PIL.py' from 'c:\\users\\user1\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
14948 INFO: Loading module hook 'hook-PIL.SpiderImagePlugin.py' from 'c:\\users\\user1\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
14951 INFO: Loading module hook 'hook-pkg_resources.py' from 'c:\\users\\user1\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
15622 INFO: Processing pre-safe import module hook win32com from 'c:\\users\\user1\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\pre_safe_import_module\\hook-win32com.py'.
15721 WARNING: Hidden import "pkg_resources.py2_warn" not found!
15943 WARNING: Hidden import "pkg_resources.markers" not found!
15945 INFO: Loading module hook 'hook-setuptools.py' from 'c:\\users\\user1\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
c:\users\user1\appdata\local\programs\python\python39\lib\site-packages\setuptools\distutils_patch.py:25: UserWarning: Distutils was imported before Setuptools. This usage is discouraged and may exhibit undesirable behaviors or errors. Please use Setuptools' objects directly or at least import Setuptools first.
  warnings.warn(
16578 INFO: Loading module hook 'hook-sysconfig.py' from 'c:\\users\\user1\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
16580 INFO: Loading module hook 'hook-win32ctypes.core.py' from 'c:\\users\\user1\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
16847 INFO: Loading module hook 'hook-xml.dom.domreg.py' from 'c:\\users\\user1\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
16849 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from 'c:\\users\\user1\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
16851 INFO: Loading module hook 'hook-xml.py' from 'c:\\users\\user1\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
16853 INFO: Loading module hook 'hook-_tkinter.py' from 'c:\\users\\user1\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
17137 INFO: checking Tree
17137 INFO: Building Tree because Tree-00.toc is non existent
17138 INFO: Building Tree Tree-00.toc
17220 INFO: checking Tree
17220 INFO: Building Tree because Tree-01.toc is non existent
17220 INFO: Building Tree Tree-01.toc
17346 INFO: checking Tree
17346 INFO: Building Tree because Tree-02.toc is non existent
17346 INFO: Building Tree Tree-02.toc
17353 INFO: Loading module hook 'hook-setuptools.msvc.py' from 'c:\\users\\user1\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
17385 INFO: Looking for ctypes DLLs
17466 INFO: Analyzing run-time hooks ...
17469 INFO: Including run-time hook 'c:\\users\\user1\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_pkgutil.py'
17475 INFO: Including run-time hook 'c:\\users\\user1\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_multiprocessing.py'
17481 INFO: Including run-time hook 'c:\\users\\user1\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_inspect.py'
17485 INFO: Including run-time hook 'c:\\users\\user1\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_pkgres.py'
17492 INFO: Including run-time hook 'c:\\users\\user1\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth__tkinter.py'
17502 INFO: Looking for dynamic libraries
18169 INFO: Looking for eggs
18169 INFO: Using Python library c:\users\user1\appdata\local\programs\python\python39\python39.dll
18170 INFO: Found binding redirects:
[]
18181 INFO: Warnings written to C:\Users\user1\build\image_ver1\warn-image_ver1.txt
18249 INFO: Graph cross-reference written to C:\Users\user1\build\image_ver1\xref-image_ver1.html
18305 INFO: checking PYZ
18305 INFO: Building PYZ because PYZ-00.toc is non existent
18305 INFO: Building PYZ (ZlibArchive) C:\Users\user1\build\image_ver1\PYZ-00.pyz
19042 INFO: Building PYZ (ZlibArchive) C:\Users\user1\build\image_ver1\PYZ-00.pyz completed successfully.
19066 INFO: checking PKG
19066 INFO: Building PKG because PKG-00.toc is non existent
19067 INFO: Building PKG (CArchive) PKG-00.pkg
29727 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
29756 INFO: Bootloader c:\users\user1\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
29756 INFO: checking EXE
29757 INFO: Building EXE because EXE-00.toc is non existent
29757 INFO: Building EXE from EXE-00.toc
29803 INFO: Copying icons from ['c:\\users\\python\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\bootloader\\images\\icon-console.ico']
29807 INFO: Writing RT_GROUP_ICON 0 resource with 104 bytes
29807 INFO: Writing RT_ICON 1 resource with 3752 bytes
29807 INFO: Writing RT_ICON 2 resource with 2216 bytes
29808 INFO: Writing RT_ICON 3 resource with 1384 bytes
29808 INFO: Writing RT_ICON 4 resource with 37019 bytes
29808 INFO: Writing RT_ICON 5 resource with 9640 bytes
29808 INFO: Writing RT_ICON 6 resource with 4264 bytes
29808 INFO: Writing RT_ICON 7 resource with 1128 bytes
29832 INFO: Updating manifest in C:\Users\user1\build\image_ver1\run.exe.3u8ql688
29834 INFO: Updating resource type 24 name 1 language 0
29858 INFO: Appending archive to EXE C:\Users\user1\dist\image_ver1.exe
34569 INFO: Building EXE from EXE-00.toc completed successfully.
PS C:\Users\user1>

該当のソースコード

import tkinter as tk
from PIL import Image, ImageTk
import pyautogui
import time
import subprocess
import os
from tkinter import filedialog
import re

#SnippingTool起動、ボタンがクリックされたら実行
def image(event):
    
 p = subprocess.Popen([r"C:\Windows\System32\SnippingTool.exe"])

selected_file = ""
#ファイル参照、ボタンがクリックされたら実行
def file_select():
  global selected_file
  idir = 'C:\\python_test' #初期フォルダ
  filetype = [("すべて","*"),("テキスト","*.txt"), ("音楽","*.mp3")] #拡張子の選択
  file_path = tk.filedialog.askopenfilename(filetypes = filetype, initialdir = idir)
  selected_file = file_path
  input_box.insert(tk.END, file_path) #結果を表示
  print(selected_file)

#画像クリック、ボタンがクリックされたら実行
def click_image():
 global selected_file

 #ファイル参照の関数からselected_fileを代入、このPCアイコンの座標を取得
 position=pyautogui.locateOnScreen(selected_file, confidence=0.9)
 #position=pyautogui.locateOnScreen("C://Users///image//excel.PNG", confidence=0.9)
 #maxwindowPCアイコンをクリック
 pyautogui.doubleClick(position)
 
# 画面作成
window = tk.Tk()
window.geometry("300x300")
window.title("ボタンを表示する")

#画像取得 ボタン作成
btn1 = tk.Button(window, text="①画像取得")
 
# ボタン表示
btn1.place(x=15, y=15, width=150, height=40)

# ボタンに関数をbind
btn1.bind("<Button-1>", image)

#入力欄の作成
input_box = tk.Entry(width=40)
input_box.place(x=10, y=100)

#結果ラベルの作成
input_label = tk.Label(text="②画像ファイル選択")
input_label.place(x=10, y=70)

#参照ボタンの作成
button = tk.Button(text="参照",command=file_select)
button.place(x=10, y=130)

#画像クリックボタンの作成
button = tk.Button(text="③画像クリック",command=click_image)
button.place(x=15, y=175, width=150, height=40)
 
# 画面表示(常駐)
window.mainloop()

お手数ですが、よろしくお願い致します。

1 件の回答 1

0

pyinstallerをアップグレードしましたら、
解決できました。

pip install --upgrade pyinstaller

Using OpenCV with PyInstaller

この質問に回答するには、ログインする必要があります。

求めていた回答ではありませんか? のタグが付いた他の質問を参照する。