pyramid.config.Configurator()不能与'with'上下文管理器一起使用

时间:2018-02-26 03:22:25

标签: pyramid

正在尝试金字塔网站中的快速入门指南:https://trypyramid.com

from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.request import Response

def hello_world(request):
    return Response('Hello World')

if __name__ == "__main__":
    with Configurator() as config:
        config.add_route('hello','/')
        config.add_view(hello_world, route_name='hello')
        app = config.make_wsgi_app()

    server = make_server('0.0.0.0',6543,app)

给出以下错误:

/anaconda3/bin/python /Users/user1/Desktop/play/pyramid_play/tut_1/exp1.py
Traceback (most recent call last):
  File "/Users/user1/Desktop/play/pyramid_play/tut_1/exp1.py", line 12, in <module>
    with Configurator() as config:
AttributeError: __enter__

Process finished with exit code 1

1 个答案:

答案 0 :(得分:1)

谢谢Steve Piercy。这是一个安装问题。我让pycharm在创建项目时安装Pyramid。 pycharm使用conda来安装包,它安装了v1.5.7(最新的conda repos)而不是1.9.1(当前版本)。 我安装了pip来安装修复问题的最新版本。