Deploy Pyramid to Elastic Beanstalk

219 views
Skip to first unread message

Andrew Burnett

unread,
Jul 17, 2016, 7:07:56 PM7/17/16
to pylons-discuss

Does anyone have experience installing a Pyramid application via Elastic Beanstalk? My application deploys but I cannot configure the application's application.py (or pyramid.wsgi) file to work properly. Within get_app the following error occurs:


File "/opt/python/run/venv/lib/python2.7/site-packages/pkg_resources/__init__.py", line 829, in resolve
[Sun Jul 17 21:24:15.482379 2016] [:error] [pid 736] [remote 127.0.0.1:9522]     raise DistributionNotFound(req, requirers)
[Sun Jul 17 21:24:15.482427 2016] [:error] [pid 736] [remote 127.0.0.1:9522] DistributionNotFound: The 'MyApp' distribution was not found and is required by the application


Where MyApp is the application I am trying to run.


Here is my application.py:


from pyramid.paster import get_app, setup_logging
import os, site, sys
ini_path = os.path.join(os.path.dirname(__file__), 'production.ini')
setup_logging(ini_path)
application = get_app(ini_path, 'main')

It seems as though the error occurs because its looking for MyApp within /opt/python/run/venv/lib/python2.7/site-packages/ rather than /opt/current/python/app/. What am I missing? Do I need to add something to my path? Does anyone have experience with this?

Michael Merickel

unread,
Jul 17, 2016, 7:30:17 PM7/17/16
to Pylons
I don't have any beanstalk experience but this is definitely a path/virtualenv issue. I'd add some code to output your sys.path and it should be clear why your code is not available. It sounds like your dependencies were installed but the package itself is not on the path.

--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discus...@googlegroups.com.
To post to this group, send email to pylons-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/94579979-dedf-4743-8f05-3d79e52a9a3f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Randall Leeds

unread,
Jul 17, 2016, 7:51:40 PM7/17/16
to Pylons

It might be that if you have a requirements.txt that Beanstalk only installs that and not your package. Listing your package as an in place, editable install with an entry like "-e ." in the requirements file will make sure that your package is linked into the environment.


Vincent Catalano

unread,
Jul 17, 2016, 11:14:07 PM7/17/16
to pylons-...@googlegroups.com
Hey Andrew,

I've deployed a number of Pyramid applications using Elastic Beanstalk. First, make sure that your Elastic Beanstalk configuration is pointing to the proper WSGIPath - I believe the default is app.py, but I would double check this value in the control panel.

Also, you will need to add a config command for your environment that runs the `setup.py develop` command. To do this, you will need to add a file to your .ebextensions folder named 01_packages.config (or use whatever naming scheme you like) with the following:

container_commands:
  01_setup:
    command: "/opt/python/run/venv/bin/python setup.py develop"

Next, run the `eb deploy` command. Elastic Beanstalk should now recognize that your package is installed.


For more options, visit https://groups.google.com/d/optout.



--
Vincent Catalano
Software Engineer and Web Ninja,
(520).603.8944

Andrew Burnett

unread,
Jul 18, 2016, 12:32:37 PM7/18/16
to pylons-discuss
Vincent,

Thank you! I'm going to try that immediately. I was wondering whether `setup.py develop` needed to be run - it only makes sense. Did you have to add any special configuration for apache or mod_wsgi in .ebextensions as well? Or add anything to the path in application.py?

Thanks,
Andrew

Andrew Burnett

unread,
Jul 18, 2016, 12:43:45 PM7/18/16
to pylons-discuss
Vincent,

You're a savior! I can't tell you how appreciate I am. What a bonehead move on my part, leaving out that command; nevertheless, adding the `setup.py develop` call in .ebextension did the trick!

Best,
Andrew

On Sunday, July 17, 2016 at 8:14:07 PM UTC-7, Vincent Catalano wrote:

Michael Merickel

unread,
Jul 18, 2016, 12:47:03 PM7/18/16
to Pylons
On Mon, Jul 18, 2016 at 11:43 AM, Andrew Burnett <ajbur...@gmail.com> wrote:
You're a savior! I can't tell you how appreciate I am. What a bonehead move on my part, leaving out that command; nevertheless, adding the `setup.py develop` call in .ebextension did the trick!

If you're using a requirements.txt and "pip install" then you should be running "pip install -e ." instead of "setup.py develop". The latter is using easy_install, instead of using pip for everything. If you've already got a requirements.txt then you should do as Randall mentioned above and just add "-e ." to the end of your requirements.txt. You may not even need the extra .ebextensions steps in that case.

- Michael

Andrew Burnett

unread,
Jul 18, 2016, 1:04:43 PM7/18/16
to pylons-discuss
Michael,

I had tried that previously but was met with the error:

'failed, because: Directory '.' is not installable. File 'setup.py' not found.'

Which I didn't understand because requirements.txt exists in the root directory of the project, at the same level as setup.py. Any ideas?

Michael Merickel

unread,
Jul 18, 2016, 1:51:42 PM7/18/16
to Pylons
On Mon, Jul 18, 2016 at 12:04 PM, Andrew Burnett <ajbur...@gmail.com> wrote:
I had tried that previously but was met with the error:

'failed, because: Directory '.' is not installable. File 'setup.py' not found.'

Which I didn't understand because requirements.txt exists in the root directory of the project, at the same level as setup.py. Any ideas?

I don't know how to fix that. It's obviously because it's not executing pip anchored to the folder containing the code / requirements.txt.

Regardless, in your .ebextensions setup you should be using "pip install -e ." instead of "python setup.py develop".

Vincent Catalano

unread,
Jul 18, 2016, 2:03:30 PM7/18/16
to pylons-...@googlegroups.com
Thanks for the insight, Michael. I will have to play around with the "-e ." option in my requirements.txt. It would definitely be nice if this could be done without the additional .ebextensions config.

--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discus...@googlegroups.com.
To post to this group, send email to pylons-...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Raymond Lau

unread,
Dec 7, 2016, 2:16:49 AM12/7/16
to pylons-discuss
Hey, I'm trying to get my Pyramid app deployed on Elastic Beanstalk.  But I'm getting the error:



[Wed Dec 07 05:42:22.567889 2016] [:error] [pid 3438] [remote 127.0.0.1:55221] ImportError: No module named 'zope.deprecation'
[Wed Dec 07 05:42:23.572279 2016] [:error] [pid 3438] [remote 127.0.0.1:59573] mod_wsgi (pid=3438): Target WSGI script '/opt/python/current/app/application.py' cannot be loaded as Python module.
[Wed Dec 07 05:42:23.572326 2016] [:error] [pid 3438] [remote 127.0.0.1:59573] mod_wsgi (pid=3438): Exception occurred processing WSGI script '/opt/python/current/app/application.py'.
[Wed Dec 07 05:42:23.572355 2016] [:error] [pid 3438] [remote 127.0.0.1:59573] Traceback (most recent call last):
[Wed Dec 07 05:42:23.572396 2016] [:error] [pid 3438] [remote 127.0.0.1:59573]   File "/opt/python/current/app/application.py", line 1, in <module>
[Wed Dec 07 05:42:23.572402 2016] [:error] [pid 3438] [remote 127.0.0.1:59573]     from pyramid.paster import get_app, setup_logging
[Wed Dec 07 05:42:23.572424 2016] [:error] [pid 3438] [remote 127.0.0.1:59573]   File "/opt/python/run/venv/lib/python3.4/site-packages/pyramid/paster.py", line 10, in <module>
[Wed Dec 07 05:42:23.572428 2016] [:error] [pid 3438] [remote 127.0.0.1:59573]     from pyramid.scripting import prepare
[Wed Dec 07 05:42:23.572447 2016] [:error] [pid 3438] [remote 127.0.0.1:59573]   File "/opt/python/run/venv/lib/python3.4/site-packages/pyramid/scripting.py", line 1, in <module>
[Wed Dec 07 05:42:23.572450 2016] [:error] [pid 3438] [remote 127.0.0.1:59573]     from pyramid.config import global_registries
[Wed Dec 07 05:42:23.572469 2016] [:error] [pid 3438] [remote 127.0.0.1:59573]   File "/opt/python/run/venv/lib/python3.4/site-packages/pyramid/config/__init__.py", line 12, in <module>
[Wed Dec 07 05:42:23.572473 2016] [:error] [pid 3438] [remote 127.0.0.1:59573]     from pyramid.interfaces import (
[Wed Dec 07 05:42:23.572490 2016] [:error] [pid 3438] [remote 127.0.0.1:59573]   File "/opt/python/run/venv/lib/python3.4/site-packages/pyramid/interfaces.py", line 1, in <module>

I tried using the application.py setup that you are using.  Did you encounter anything like this?  I followed everything that has been mentioned in this thread (ex. regarding the requirements.txt and pip install -e .)

Vincent Catalano

unread,
Dec 7, 2016, 9:16:24 AM12/7/16
to pylons-...@googlegroups.com
What does your requirements.txt file look like?

--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+unsubscribe@googlegroups.com.
To post to this group, send email to pylons-discuss@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/fb78a2c5-5073-4fe3-8887-720791b26700%40googlegroups.com.

Raymond Lau

unread,
Dec 7, 2016, 5:44:08 PM12/7/16
to pylons-discuss
beautifulsoup4==4.5.1
Chameleon==2.25
coverage==4.2
Mako==1.0.6
MarkupSafe==0.23
PasteDeploy==1.5.2
py==1.4.31
Pygments==2.1.3
pyramid==1.7.3
pyramid-chameleon==0.3
pyramid-debugtoolbar==3.0.5
pyramid-mako==1.0.2
pytest==3.0.5
pytest-cov==2.4.0
repoze.lru==0.6
six==1.10.0
translationstring==1.3
venusian==1.0
waitress==1.0.1
WebOb==1.6.3
WebTest==2.0.23
zope.deprecation==4.2.0
zope.interface==4.3.2

When I add "-e ." to the requirements.txt, as mentioned by Randall, I get the error from EB: "caused by: Directory '.' is not installable. File 'setup.py' not found."  However, it'll work fine locally via "pip install -r requirements.txt".
To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discus...@googlegroups.com.
To post to this group, send email to pylons-...@googlegroups.com.

Vincent Catalano

unread,
Dec 12, 2016, 2:06:09 AM12/12/16
to pylons-...@googlegroups.com
I realized that the "-e ." in the requirements.txt did not work for me either when I attempted this. I believe this is because AWS uses a different staging folder for configuring the project requirements that does not have access to the project packages. The only way I was able to get the package installed was by adding a new .ebextensions script with the following:

container_commands:
  01_setup:
    command: "/opt/python/run/venv/bin/python setup.py develop"
To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+unsubscribe@googlegroups.com.
To post to this group, send email to pylons-discuss@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/2367b0c1-062c-4e56-84e8-f9f178448ee0%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Vincent Catalano
Software Engineer and Consultant,
(520).603.8944
Reply all
Reply to author
Forward
0 new messages