danclark
danclark

Reputation: 111

No module named 'zope.deprecation' with simple hello world pyramid app

I am trying to learn how to deploy a pyramid app to AWS (Elastic Beanstalk), and I am taking it step by step, but I am stuck. I am using the hello world app in order to keep it simple, but I am getting the following error and I don't know why:

[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'

Code that I am trying to deploy is below. I uploaded this via the console.

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()

Steps I have taken:

SSH'ed into the instance and installed pyramid via

sudo /opt/python/run/venv/bin/pip install pyramid

Checked pip freeze and it is present and in the correct 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)

I've tried to invoke the module from python directly without success

(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'
>>> 

Interestingly, help('modules') doesn't show it, but it does show pyramid. I've also tried to install it directly. The module is in /opt/python/run/venv/local/lib/python3.4/site-packages.

I am out of ideas, and I am tempted to ditch this approach and try the EB CLI.

This sounds like I am missing something really obvious. Also, since this is a simple one file script I don't have a setup.py to run.

Other things I have tried:

One of the last steps have made python able to recognize zope.deprecation. App still doesn't work as it is back to

Target WSGI script '/opt/python/current/app/application.py' does not contain WSGI application 'application'.

Not sure if this is progress or not.

UPDATE

GOT IT WORKING. I think the secret was rolling back versions, adding a requirements.txt, and changing the location of the application variable in application.py.

application.py now looks like

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()

I will experiment and hopefully add a better answer.

Upvotes: 1

Views: 1076

Answers (2)

danclark
danclark

Reputation: 111

I don't have a reason yet, but the quick answer is that I needed to use zope.deprecation 4.1.2. Version 4.2 was causing things to break.

Upvotes: 0

Michael Merickel
Michael Merickel

Reputation: 23331

Errors like these occur frequently when mixing setup.py <foo> with pip install <bar> due to how each system handles namespace packages (like zope.XXX). The solution is usually to blow everything away and then install it using only one tool. For example if you're using python setup.py develop right now, replace it with pip install -e .

Upvotes: 2

Related Questions