Import Error: No module named AppKit

人走茶凉 提交于 2021-02-04 17:13:27

问题


I use Mac OS X Lion and Python 2.7. I am new to python. Can anyone tell me how to import AppKit and PyObjC to Python. But i get the errors when trying to import Import Error: No module named AppKit or 'Import Error: No module named PyObjC.

Trying easy_install does not help either. This is a screenshot when I run <code>easy_install PyObjC</code>

What can i do to import these 2 modules?


回答1:


If not already installed, install pip by running:

sudo easy_install pip

Then run:

## install for all users
sudo pip install pyobjc

or

## install for current user only
pip install pyobjc --user

NOTE: the general recommendation is to avoid using the system python, and use instead a user-maintained version, for example installed via brew install python3, macports, conda or whatever you already use for third party dependencies.




回答2:


If you're on Mac it could be you're using the incorrect pip version, try sudo pip3 install -U pyobjc that solved it for me.




回答3:


This a good guide on how to install PyObjc: http://ioanna.me/2009/09/installing-pyobjc-xcode-templates-in-snow-leopard/

When I was trying to install PyObjc I found it quite hard, but after a while, (and lots of google searches) I got it working.

Edit

I've found a more modern guide on how to do this. Download the templates and put them into your ~/Library/Developer/Xcode/Templates/ directory, and everything should work correctly.




回答4:


If you are using PyCharm, you should install PyObjC package manually within it because of venv I guess. This was the only working solution for me.



来源:https://stackoverflow.com/questions/12767669/import-error-no-module-named-appkit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!