本文介绍了导入错误:没有名为 Foundation 的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试按照使用 Xcode 3.2 进行 PyObjC 开发"的已接受答案的说明进行操作.我将在此处重新发布它们,因为我没有足够的代表来评论实际问题:

以下是我为让 PyObjC 在 Snow Leopard 中工作所做的工作:

  • 使用 Finder,我去了 Go >连接到服务器... 并连接到 http://svn.red-bean.com/pyobjc/trunk/pyobjc/pyobjc-xcode/ 作为访客.

  • 然后我在本地系统上的 ~Library/Application Support/Developer/Shared/Xcode/ 创建了一个名为 Xcode 的文件夹.(你可能已经有了这个文件夹,但我还没有为自己定制任何东西).

  • 我将 File Templates 文件夹从红豆服务器复制到我的新 Xcode 文件夹中.

  • Project Templates 文件夹复制到其他地方,例如桌面.

  • 使用终端,导航到我桌面上的临时项目模板文件夹并运行此命令以构建"模板.:

$ cd ~/桌面/项目\模板/

$ ./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

当我尝试运行以 ./project-tool.py 开头的行时,我在终端中收到以下错误:

回溯(最近一次调用最后一次): 中的文件./project-tool.py",第 22 行从 Foundation 导入 NSDictionary导入错误:没有名为 Foundation 的模块

我正在运行 Snow Leopard 并且已经安装了 Xcode 3.2.1 并且已经读到这个模块应该已经安装并且可以工作.我已经读到您可以通过运行 >>>> 来测试 PyObjC 模块是否正常工作.在 Python 命令行中导入 objc.当我运行这个时,我得到:

>>>导入对象回溯(最近一次调用最后一次):文件<stdin>",第 1 行,在 <module> 中导入错误:没有名为 objc 的模块

谁能帮我消除这个错误?似乎我应该能够通过安装 Snow Leopard 自动完成所有这些操作,但我不能.

解决方案

好吧,事实证明,修改 mjv 的答案后,我可以通过输入使其正常工作

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

在执行 ./project-tool.py 行之前.我仍然觉得我必须这样做很荒谬,如果有人能明白为什么,我会很高兴知道.

这样做也得到了

>>>导入对象

流水线作业.

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.:


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.

解决方案

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.

这篇关于导入错误:没有名为 Foundation 的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 16:04