运行示例金字塔程序时出错:ImportError: 没有名为execptions的模块

-2 投票
1 回答
1403 浏览
提问于 2025-04-17 09:06

我刚开始学习Python和Pyramid框架。今天我在我的Mac上安装了Pyramid,而我的电脑上已经预装了Python 2.7.1。我按照官网上的说明安装了Pyramid。我使用了官网提到的nositepackages的虚拟环境,并把Pyramid安装在我的/users/sreekanth目录下。

安装完成后,我尝试运行官网上提到的第一个示例程序,具体内容可以在文档中找到

但是当我尝试运行这个程序时,出现了一个错误,错误信息如下。

sreekanths-MacBook-Pro:tasks Sreekanth$ ../bin/python2.7 tasks.py
Traceback (most recent call last):
  File "tasks.py", line 87, in <module>
    config.scan()
  File "/Users/Sreekanth/env/lib/python2.7/site-packages/pyramid-1.3a3-py2.7.egg/pyramid/config/__init__.py", line 893, in scan
    scanner.scan(package, categories=categories, onerror=onerror)
  File "/Users/Sreekanth/env/lib/python2.7/site-packages/venusian-1.0a2-py2.7.egg/venusian/__init__.py", line 95, in scan
    invoke(name, ob)
  File "/Users/Sreekanth/env/lib/python2.7/site-packages/venusian-1.0a2-py2.7.egg/venusian/__init__.py", line 92, in invoke
    callback(self, name, ob)
  File "/Users/Sreekanth/env/lib/python2.7/site-packages/pyramid-1.3a3-py2.7.egg/pyramid/view.py", line 210, in callback
    config.add_view(view=ob, **settings)
  File "/Users/Sreekanth/env/lib/python2.7/site-packages/pyramid-1.3a3-py2.7.egg/pyramid/config/views.py", line 575, in wrapper
    return wrapped(*arg, **defaults)
  File "/Users/Sreekanth/env/lib/python2.7/site-packages/pyramid-1.3a3-py2.7.egg/pyramid/config/util.py", line 59, in wrapper
    result = wrapped(self, *arg, **kw)
  File "/Users/Sreekanth/env/lib/python2.7/site-packages/pyramid-1.3a3-py2.7.egg/pyramid/config/views.py", line 926, in add_view
    context = self.maybe_dotted(context)
  File "/Users/Sreekanth/env/lib/python2.7/site-packages/pyramid-1.3a3-py2.7.egg/pyramid/config/__init__.py", line 808, in maybe_dotted
    return self.name_resolver.maybe_resolve(dotted)
  File "/Users/Sreekanth/env/lib/python2.7/site-packages/pyramid-1.3a3-py2.7.egg/pyramid/path.py", line 318, in maybe_resolve
    return self._resolve(dotted, package)
  File "/Users/Sreekanth/env/lib/python2.7/site-packages/pyramid-1.3a3-py2.7.egg/pyramid/path.py", line 325, in _resolve
    return self._zope_dottedname_style(dotted, package)


  File "/Users/Sreekanth/env/lib/python2.7/site-packages/pyramid-1.3a3-py2.7.egg/pyramid/path.py", line 374, in _zope_dottedname_style
    __import__(used)
ImportError: No module named execptions

而且我在Python命令行中也无法导入Pyramid模块。下面是我收到的错误信息。

sreekanths-MacBook-Pro:bin Sreekanth$ pwd
/Users/Sreekanth/env/bin
sreekanths-MacBook-Pro:bin Sreekanth$ python
Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyramid
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named pyramid

有人能告诉我我缺少了什么,或者我该怎么做才能让它正常工作吗?

1 个回答

5

第一个错误说明你的程序里有个拼写错误。很可能你写成了

from pyramid.execptions import NotFound

而应该写成

from pyramid.exceptions import NotFound
#              ^^

另外,由于你把pylons/pyramid安装到了一个虚拟环境里,你需要先激活这个环境。在命令行中输入 source bin/activate 就可以了。这样会设置正确的Python路径,你可以通过在Python控制台查看 sys.path 来确认。

撰写回答