Python 3 No Module Named AppKit

user5124826 picture user5124826 · Nov 13, 2017 · Viewed 7.5k times · Source

I am trying to run an audio file in python

from playsound import playsound

def main():
    playsound('audio.mp3')

main()

However, I keep getting the following error:

File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/playsound.py", line 55, in _playsoundOSX
from AppKit     import NSSound
ImportError: No module named 'AppKit'

I am using Python 3.5.4 on macOS 10.12.6. I have tried installing it via pip but I am returned this error:

Using cached AppKit-0.2.8.tar.gz
Requirement already satisfied: flask in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages (from appkit)
Collecting pygobject (from appkit)
Could not find a version that satisfies the requirement pygobject (from appkit) (from versions: )
No matching distribution found for pygobject (from appkit)

Answer

xern picture xern · Nov 14, 2017

If you want to use AppKit you have to install PyObjC:

pip3 install -U PyObjC

or

pip install -U PyObjC