views:

573

answers:

5

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.

A: 

One of two things:

  • Either the Fundation module doesn't exists
  • Or Python interpretor doesn't know when to find this file

Python looks for modules in the PythonPath

See this SO question for more details on how Python Path is created etc.

mjv
Thank you for this. It is useful to know how to edit the Python Path. Unfortunately, though, I have no idea what path I should be adding in order to incorporate Foundation.
Chris Redford
A: 

Run python -v to trace import statements, this work for interactive mode too.

Denis Otkidach
Sorry, I ran this and I did get output. I just don't understand what I am supposed to be looking for.
Chris Redford
+1  A: 

Okay, it turned out that, amending mjv's answer, I was able to get it working by typing

export PYTHONPATH="/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/PyObjC/"

before executing the ./project-tool.py line. I still find it ridiculous that I had to do this and if anyone can see why, I would be delighted to know.

Doing this also got the

>>> import objc

line working.

Chris Redford
A: 

I'm having the same error and so tried this with a 2.6 install (changing 2.5 to 2.6) but there is no PyObjC file in the site-packages directory. I have definitely installed PyObjC though! Any ideas??

brainysmurf
+1  A: 

It's because PyObjC is there : /System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC

Edit : I found how to make "import objc" work, just : export PYTHONPATH="/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/"

It will add all the directories to the python path (sys.path)

ThmX