asweigart / pyautogui

A cross-platform GUI automation Python module for human beings. Used to programmatically control the mouse & keyboard.
BSD 3-Clause "New" or "Revised" License
10.32k stars 1.25k forks source link

Import errors on MacOS having to do with PyObjC installation #499

Open loganfred opened 3 years ago

loganfred commented 3 years ago

macOS Catalina v. 10.15.7

This is really confusing to me and I can't figure it out. Installation goes fine (no red output or anything) but as soon as I try to actually use Pyautogui I get some kind of runtime assertion error.

Repro Steps:

  1. install Python 3.7 via brew
> brew install python@3.7
  1. create and activate virtual environment
> /usr/local/opt/python@3.7/bin/python3.7 -m venv venv

> source venv/bin/activate
  1. install pyautogui
(venv) > python -m pip install pyautogui
  1. test
Python 3.7.9 (default, Nov 20 2020, 18:45:38)
[Clang 12.0.0 (clang-1200.0.32.27)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyautogui
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/pyautogui/_pyautogui_osx.py", line 5, in <module>
    import Quartz
  File "/usr/local/lib/python3.7/site-packages/Quartz/__init__.py", line 6, in <module>
    import AppKit
  File "/usr/local/lib/python3.7/site-packages/AppKit/__init__.py", line 10, in <module>
    import Foundation
  File "/usr/local/lib/python3.7/site-packages/Foundation/__init__.py", line 9, in <module>
    import CoreFoundation
  File "/usr/local/lib/python3.7/site-packages/CoreFoundation/__init__.py", line 16, in <module>
    objc.pathForFramework("/System/Library/Frameworks/CoreFoundation.framework"),
  File "/usr/local/lib/python3.7/site-packages/objc/_dyld.py", line 148, in pathForFramework
    fpath, name, version = infoForFramework(dyld_find(path))
  File "/usr/local/lib/python3.7/site-packages/objc/_dyld.py", line 142, in dyld_find
    return dyld_framework(filename, framework_name, version)
  File "/usr/local/lib/python3.7/site-packages/objc/_dyld.py", line 101, in dyld_framework
    if _dyld_shared_cache_contains_path(f):
NotImplementedError: _dyld_shared_cache_contains_path not available

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/pyautogui/__init__.py", line 536, in <module>
    from . import _pyautogui_osx as platformModule
  File "/usr/local/lib/python3.7/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
  1. sanity test
(venv) > python -m pip freeze
MouseInfo==0.1.3
Pillow==8.0.1
PyAutoGUI==0.9.52
PyGetWindow==0.0.9
PyMsgBox==1.0.9
pynput==1.7.1
pyobjc==7.0
pyobjc-core==7.0
pyobjc-framework-Accounts==7.0
pyobjc-framework-AddressBook==7.0
pyobjc-framework-AdSupport==7.0
pyobjc-framework-AppleScriptKit==7.0
pyobjc-framework-AppleScriptObjC==7.0
pyobjc-framework-ApplicationServices==7.0
pyobjc-framework-AuthenticationServices==7.0
pyobjc-framework-AutomaticAssessmentConfiguration==7.0
pyobjc-framework-Automator==7.0
pyobjc-framework-AVFoundation==7.0
pyobjc-framework-AVKit==7.0
pyobjc-framework-BusinessChat==7.0
pyobjc-framework-CalendarStore==7.0
pyobjc-framework-CFNetwork==7.0
pyobjc-framework-CloudKit==7.0
pyobjc-framework-Cocoa==7.0
pyobjc-framework-Collaboration==7.0
pyobjc-framework-ColorSync==7.0
pyobjc-framework-Contacts==7.0
pyobjc-framework-ContactsUI==7.0
pyobjc-framework-CoreAudio==7.0
pyobjc-framework-CoreAudioKit==7.0
pyobjc-framework-CoreBluetooth==7.0
pyobjc-framework-CoreData==7.0
pyobjc-framework-CoreHaptics==7.0
pyobjc-framework-CoreLocation==7.0
pyobjc-framework-CoreMedia==7.0
pyobjc-framework-CoreMediaIO==7.0
pyobjc-framework-CoreMIDI==7.0
pyobjc-framework-CoreML==7.0
pyobjc-framework-CoreMotion==7.0
pyobjc-framework-CoreServices==7.0
pyobjc-framework-CoreSpotlight==7.0
pyobjc-framework-CoreText==7.0
pyobjc-framework-CoreWLAN==7.0
pyobjc-framework-CryptoTokenKit==7.0
pyobjc-framework-DeviceCheck==7.0
pyobjc-framework-DictionaryServices==7.0
pyobjc-framework-DiscRecording==7.0
pyobjc-framework-DiscRecordingUI==7.0
pyobjc-framework-DiskArbitration==7.0
pyobjc-framework-DVDPlayback==7.0
pyobjc-framework-EventKit==7.0
pyobjc-framework-ExceptionHandling==7.0
pyobjc-framework-ExecutionPolicy==7.0
pyobjc-framework-ExternalAccessory==7.0
pyobjc-framework-FileProvider==7.0
pyobjc-framework-FileProviderUI==7.0
pyobjc-framework-FinderSync==7.0
pyobjc-framework-FSEvents==7.0
pyobjc-framework-GameCenter==7.0
pyobjc-framework-GameController==7.0
pyobjc-framework-GameKit==7.0
pyobjc-framework-GameplayKit==7.0
pyobjc-framework-ImageCaptureCore==7.0
pyobjc-framework-IMServicePlugIn==7.0
pyobjc-framework-InputMethodKit==7.0
pyobjc-framework-InstallerPlugins==7.0
pyobjc-framework-InstantMessage==7.0
pyobjc-framework-Intents==7.0
pyobjc-framework-IOSurface==7.0
pyobjc-framework-iTunesLibrary==7.0
pyobjc-framework-LatentSemanticMapping==7.0
pyobjc-framework-LaunchServices==7.0
pyobjc-framework-libdispatch==7.0
pyobjc-framework-LinkPresentation==7.0
pyobjc-framework-LocalAuthentication==7.0
pyobjc-framework-MapKit==7.0
pyobjc-framework-MediaAccessibility==7.0
pyobjc-framework-MediaLibrary==7.0
pyobjc-framework-MediaPlayer==7.0
pyobjc-framework-MediaToolbox==7.0
pyobjc-framework-Metal==7.0
pyobjc-framework-MetalKit==7.0
pyobjc-framework-MetalPerformanceShaders==7.0
pyobjc-framework-ModelIO==7.0
pyobjc-framework-MultipeerConnectivity==7.0
pyobjc-framework-NaturalLanguage==7.0
pyobjc-framework-NetFS==7.0
pyobjc-framework-Network==7.0
pyobjc-framework-NetworkExtension==7.0
pyobjc-framework-NotificationCenter==7.0
pyobjc-framework-OpenDirectory==7.0
pyobjc-framework-OSAKit==7.0
pyobjc-framework-OSLog==7.0
pyobjc-framework-PencilKit==7.0
pyobjc-framework-Photos==7.0
pyobjc-framework-PhotosUI==7.0
pyobjc-framework-PreferencePanes==7.0
pyobjc-framework-PushKit==7.0
pyobjc-framework-Quartz==7.0
pyobjc-framework-QuickLookThumbnailing==7.0
pyobjc-framework-SafariServices==7.0
pyobjc-framework-SceneKit==7.0
pyobjc-framework-ScreenSaver==7.0
pyobjc-framework-ScriptingBridge==7.0
pyobjc-framework-SearchKit==7.0
pyobjc-framework-Security==7.0
pyobjc-framework-SecurityFoundation==7.0
pyobjc-framework-SecurityInterface==7.0
pyobjc-framework-ServiceManagement==7.0
pyobjc-framework-Social==7.0
pyobjc-framework-SoundAnalysis==7.0
pyobjc-framework-Speech==7.0
pyobjc-framework-SpriteKit==7.0
pyobjc-framework-StoreKit==7.0
pyobjc-framework-SyncServices==7.0
pyobjc-framework-SystemConfiguration==7.0
pyobjc-framework-SystemExtensions==7.0
pyobjc-framework-UserNotifications==7.0
pyobjc-framework-VideoSubscriberAccount==7.0
pyobjc-framework-VideoToolbox==7.0
pyobjc-framework-Vision==7.0
pyobjc-framework-WebKit==7.0
pyperclip==1.8.1
PyRect==0.1.4
PyScreeze==0.1.26
PyTweening==1.0.3
rubicon-objc==0.4.0
six==1.15.0
loganfred commented 3 years ago

I did also try this thing and no luck.

MACOSX_DEPLOYMENT_TARGET=10.11 pip install pyobjc
hwangwoohyun-nav commented 3 years ago

Facing same issue while importing pyautogui MacOS version 10.15.7

asweigart commented 3 years ago

On my macOS Catalina 10.15.7 machine running Python 3.8, I'm installing PyAutoGUI and getting pyobjc 7.3 and can import it just fine.

Can others chime in on if they're getting this error?

JayRizzo commented 2 years ago

Hey @asweigart,

I wrote up about this on issue #495 .

A fresh install resolves this issue. if that is too much try removing the other variations of python installations from your computer. I suspect that is the issue.

In python 3.10.5 a fresh install accompanied with pip3 install pyautogui doesn't seem to have this issue.

https://github.com/asweigart/pyautogui/issues/495#issuecomment-1172557674