没有名为'zope.deprecation'的模块与简单的hello world金字塔应用程序



我正在尝试学习如何将金字塔应用程序部署到AWS(Elastic Beanstalk),而我正在逐步进行,但我被卡住了。我正在使用Hello World应用程序来保持简单,但是我会收到以下错误,我不知道为什么:

[Mon Feb 20 18:08:33.477650 2017] [:error] [] mod_wsgi (pid=2811): Target WSGI script '/opt/python/current/app/application.py' cannot be loaded as Python module.
[Mon Feb 20 18:08:33.477918 2017] [:error] [] mod_wsgi (pid=2811): Exception occurred processing WSGI script '/opt/python/current/app/application.py'.
[Mon Feb 20 18:08:33.478124 2017] [:error] [] [remote 69.127.251.49:45648] Traceback (most recent call last):
[Mon Feb 20 18:08:33.478329 2017] [:error] []   File "/opt/python/current/app/application.py", line 2, in <module>
[Mon Feb 20 18:08:33.478440 2017] [:error] []     from pyramid.config import Configurator
[Mon Feb 20 18:08:33.478630 2017] [:error] []   File "/opt/python/run/venv/lib/python3.4/site-packages/pyramid/config/__init__.py", line 12, in <module>
[Mon Feb 20 18:08:33.478745 2017] [:error] []     from pyramid.interfaces import (
[Mon Feb 20 18:08:33.478923 2017] [:error] []   File "/opt/python/run/venv/lib/python3.4/site-packages/pyramid/interfaces.py", line 1, in <module>
[Mon Feb 20 18:08:33.479050 2017] [:error] []     from zope.deprecation import deprecated
[Mon Feb 20 18:08:33.479213 2017] [:error] [] ImportError: No module named 'zope.deprecation'

我试图部署的代码在下面。我通过控制台上传了此。

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

def hello_world(request):
    return Response('Hello %(name)s!' % request.matchdict)
if __name__ == '__main__':
    config = Configurator()
    config.add_route('hello', '/hello/{name}')
    config.add_view(hello_world, route_name='hello')
    application = config.make_wsgi_app()
    server = make_server('', 8000, application)
    server.serve_forever()

我采取的步骤:

sshed到实例中,并通过

安装了金字塔

sudo/opt/python/run/venv/bin/pip安装金字塔

检查pip冻结,并且存在于正确的VENV

(venv)[ec2-user@ ~]$ pip list
hupper (0.4.2)
PasteDeploy (1.5.2)
pip (7.1.2)
pyramid (1.8.2)
repoze.lru (0.6)
setuptools (18.4)
translationstring (1.3)
venusian (1.0)
WebOb (1.7.1)
zope.deprecation (4.2.0)
zope.interface (4.3.3)
(venv)[ec2-user@ ~]$ pip --version
pip 7.1.2 from /opt/python/run/venv/local/lib/python3.4/site-packages(python 3.4)

我尝试直接从Python调用该模块而没有成功

(venv)[ec2-user@ ~]$ python
Python 3.4.3 (default, Sep  1 2016, 23:33:38) 
[GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from zope.deprecation import deprecation
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'zope.deprecation'
>>> 

有趣的是,help('modules')没有显示它,但确实显示了金字塔。我还尝试直接安装它。该模块在/opt/python/run/venv/local/lib/python3.4/site-packages中。

我没有想法,我很想抛弃这种方法并尝试EB CLI。

这听起来像我缺少明显的东西。另外,由于这是一个简单的一个文件脚本,所以我没有设置。py可以运行。

我尝试过的其他事情:

  • 吹走整个应用程序,然后重试。
  • 尝试金字塔1.7和Zope.Deprection 4.1.2在新应用程序上。
  • 尝试使用requient.txt文件。

最后一个步骤之一使Python能够识别Zope.Deprection。应用程序仍然无法正常工作,因为它又回到

target wsgi脚本'/opt/python/current/app/application.py'不包含WSGI应用程序'应用程序'。

不确定这是否进展。

更新

使它起作用。我认为秘密是回滚版本,添加了unignt.txt,并更改了应用程序变量的位置。

application.py现在看起来像

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

def hello_world(request):
    return Response('Hello %(name)s!' % request.matchdict)
config = Configurator()
config.add_route('hello', '/hello/{name}')
config.add_view(hello_world, route_name='hello')
application = config.make_wsgi_app()
if __name__ == '__main__':  
    server = make_server('', 8000, application)
    server.serve_forever()

我会尝试并希望添加一个更好的答案。

类似错误的错误在将setup.py <foo>pip install <bar>混合时经常发生,因为每个系统如何处理名称空间软件包(例如zope.XXX)。解决方案通常是要吹走所有内容,然后仅使用一个工具安装它。例如,如果您现在使用python setup.py develop,请用pip install -e .

替换它

我还没有理由,但是快速答案是我需要使用zope.deprection 4.1.2。版本4.2导致事情破裂。

相关内容

最新更新