No Module Named AppKit
Asked Answered
J

4

21

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)
Jabot answered 13/11, 2017 at 17:41 Comment(2)
Looks like you forgot to install pyobjc...Butane
@Lukas I installed pyobjc; still getting the same error. Pyobjc was installed to the Python 2.x directory. I'm using Python 3Jabot
U
39

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

pip3 install -U PyObjC

or

pip install -U PyObjC
Unicef answered 14/11, 2017 at 9:5 Comment(0)
T
4

If anybody else stumbles upon this error when using this library, trying to do exactly as @user5124826 first stated in the question, as long as you have you have done a:

pip3 install AppKit

or

pip install AppKit

And also installed PyObjC...Wherever you have your packages installed, for example, pip when used with virtualenv will generally install packages in the path

virtualenv_name>/lib//site-packages.

Look for the AppKit package, and it will most likely be in all LOWERCASE. So it would be appkit. Just change this folder to 'AppKit', and you should be good to go

Tishatishri answered 11/10, 2019 at 3:23 Comment(1)
Same problem for me (suddenly, probably after some brew updates etc.). However, if I rename as suggested I'm not getting AttributeError: module 'AppKit' has no attribute 'NSWorkspace'Melena
M
0

Ran into the same problem (suddenly, probaby after some system upgrade of brew, etc.).

I solved it by reinstalling from scratch, following iTerm's docs.

pip uninstall appkit
pip uninstall iterm2
pip list | grep pyobjc | cut -d ' ' -f 1 | xargs pip uninstall -y

then, depending on your system

pyenv rehash

then reinstall only iterm2

pip install iterm2

According to the docs, iterm2 has pyobjc as a dependency and it all provides AppKit, so no additional installation needed.

Melena answered 24/5, 2021 at 9:42 Comment(0)
F
0

In my case, it works only in Python 2.7. Because Python 3 requires small letters, in import appkit you get the error.

I have updated a library to work with small caps import: https://github.com/TinKurbatoff/appkit

Felucca answered 10/7, 2021 at 0:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.