以下のプログラムを走らせます。
import pyautogui
import time
# Kindleアプリがアクティブになるのを待つための遅延
time.sleep(5)
pyautogui.press('right')
すると以下のエラーが出ました。
Traceback (most recent call last):
File "/Users/user/Library/Python/3.10/lib/python/site-packages/pyautogui/_pyautogui_osx.py", line 5, in <module>
import Quartz
File "/Users/user/Library/Python/3.10/lib/python/site-packages/Quartz/__init__.py", line 6, in <module>
import AppKit
File "/Users/user/Library/Python/3.10/lib/python/site-packages/AppKit/__init__.py", line 10, in <module>
import Foundation
File "/Users/user/Library/Python/3.10/lib/python/site-packages/Foundation/__init__.py", line 9, in <module>
import CoreFoundation
File "/Users/user/Library/Python/3.10/lib/python/site-packages/CoreFoundation/__init__.py", line 9, in <module>
import objc
File "/Users/user/Library/Python/3.10/lib/python/site-packages/objc/__init__.py", line 6, in <module>
from . import _objc
ImportError: cannot import name '_objc' from partially initialized module 'objc' (most likely due to a circular import) (/Users/user/Library/Python/3.10/lib/python/site-packages/objc/__init__.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/user/Dropbox/python/source_code/text2_kindle_screenshot.py", line 1, in <module>
import pyautogui
File "/Users/user/Library/Python/3.10/lib/python/site-packages/pyautogui/__init__.py", line 540, in <module>
from . import _pyautogui_osx as platformModule
File "/Users/user/Library/Python/3.10/lib/python/site-packages/pyautogui/_pyautogui_osx.py", line 7, in <module>
assert False, "You must first install pyobjc-core and pyobjc: https://pyautogui.readthedocs.io/en/latest/install.html"
AssertionError: You must first install pyobjc-core and pyobjc: https://pyautogui.readthedocs.io/en/latest/install.html
どうやらライブラリが正常に動作できていないらしいです。
以下のコマンドでライブラリを再インストールしたら正常に動作しました。
pip3 install --upgrade --force-reinstall pyobjc-core pyobjc
pip3 install --upgrade --force-reinstall pyautogui
ようやくスタートラインに立ちました。
ここからkindleのテキスト化、音声化プログラムを作っていきます。