Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
289 views
in Technique[技术] by (71.8m points)

python - ImportError: No module named Foundation

I am trying to follow the instructions for the accepted answer to "PyObjC development with Xcode 3.2". I will repost them here since I don't have enough rep to comment on the actual question:


Here's what I have done to get PyObjC working in Snow Leopard:

  • Using the Finder, I went to Go > Connect to Server... and connected to http://svn.red-bean.com/pyobjc/trunk/pyobjc/pyobjc-xcode/ as a guest.

  • I then made a folder called Xcode on my local system at ~Library/Application Support/Developer/Shared/Xcode/. (You may already have this folder, but I hadn't customized anything for myself yet).

  • I copied the File Templates folder from the red-bean server into my new Xcode folder.

  • Copied the Project Templates folder to some other place, for example, the Desktop.

  • Using the Terminal, navigated to the temporary Project Templates folder on my Desktop and ran this command to "build" the template.:

$ cd ~/Desktop/Project Templates/

$ ./project-tool.py -k -v --template ~/Desktop/Project Templates/Cocoa-Python Application/CocoaApp.xcodeproj/TemplateInfo.plist Cocoa-Python Application ~/Library/Application Support/Developer/Shared/Xcode/Project Templates/Cocoa-Python Application


When I try to run the line that starts with ./project-tool.py, I get the following error in Terminal:

Traceback (most recent call last):  
  File "./project-tool.py", line 22, in <module>  
     from Foundation import NSDictionary  
 ImportError: No module named Foundation

I am running Snow Leopard and have installed Xcode 3.2.1 and have read that this module should already be installed and working. I've read that you can test if the PyObjC modules are working by running >>> import objc in the Python command-line. When I run this, I get:

>>> import objc
Traceback (most recent call last):  
  File "<stdin>", line 1, in <module>  
ImportError: No module named objc  

Could anyone help me dispel this error? It seems like I should be able to do all of this automatically with my Snow Leopard installation, but I can't.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I had the same problem. Mine was caused I think by using homebrew to install my own Python to tinker with.

Because I was worried about mixing python versions, rather than creating the link as described above, I installed a new pyobjc using:

$ pip install pyobjc

For interest, from (http://pythonhosted.org/pyobjc/)

The PyObjC project aims to provide a bridge between the Python and Objective-C programming languages.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...