Python3.9下PyAutoGUI报错:'pyautogui._pyautogui_osx'无_size属性求助
Hey there! I see you're dipping your toes into automation scripts and ran into a compatibility snag between PyAutoGUI, Rubicon, and Python 3.9 on macOS. Let's break down what's happening and get you back on track.
What's Causing This?
The AttributeError: module 'pyautogui._pyautogui_osx' has no attribute '_size' error pops up for two key reasons:
- The Rubicon library (which PyAutoGUI relies on to interact with macOS) was only tested up to Python 3.8 when you installed it. Python 3.9 had internal changes that broke some of its functionality.
- PyAutoGUI's macOS-specific module (
_pyautogui_osx) wasn't updated to work with Python 3.9 at the time you installed it, leading to missing critical attributes like_size.
Step-by-Step Solutions
1. Downgrade Python to 3.8 (Most Reliable Fix)
Since the Rubicon warning explicitly states it’s fully tested up to Python 3.8, this will eliminate both the warning and the error:
- If you use a version manager like
pyenv, install and switch to Python 3.8:pyenv install 3.8.10 pyenv local 3.8.10 - Or download Python 3.8 directly from the official Python website, then reinstall PyAutoGUI:
pip3 install pyautogui
2. Upgrade PyAutoGUI to the Latest Version
Later releases of PyAutoGUI fixed compatibility with Python 3.9 on macOS. Try updating first—it’s quick and might solve the issue without changing your Python version:
pip3 install --upgrade pyautogui
This will also pull in an updated Rubicon version that supports newer Python releases.
3. Quick Script Check (Once the Error is Fixed)
After resolving the import issue, double-check this small detail in your code:
- The file you’re opening is named
"requirements"—make sure this file exists in the same folder as your script, and that it’s not a typo (tutorials often use files like"messages.txt"for this use case). Test with a simple text file containing a few lines of sample messages to confirm it works.
Error Context (For Reference)
You first saw this warning:
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/rubicon/objc/ctypes_patch.py:21: UserWarning: rubicon.objc.ctypes_patch has only been tested with Python 3.4 through 3.8. You are using Python 3.9.0. Most likely things will work properly, but you may experience crashes if Python's internals have changed significantly.
warnings.warn(
Followed by this traceback:
Traceback (most recent call last):
File "/Users/davidbonavia/PycharmProjects/pythonProject3/testtchatbot.py", line 2, in
import pyautogui
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pyautogui/init.py", line 2144, in
_right, _bottom = size()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pyautogui/init.py", line 769, in size
return Size(*platformModule._size())
AttributeError: module 'pyautogui._pyautogui_osx' has no attribute '_size'
Give one of the first two solutions a go—either downgrading Python or upgrading PyAutoGUI should get your auto-messaging script up and running smoothly!
内容的提问来源于stack exchange,提问作者user14478909

