简体   繁体   中英

Getting error from beanstalk when trying to deploy flask app: “no module named flask”

I've been trying to figure out this problem for a while but can't figure it out. My app structure is like this:

myapp  
    -application.py  
    -myapp  
       -sample.css  
       -sample.js  
       -blueprints.py  
       -__init__.py  
       -__init__.pyc  
       -templates  
         -base.jinja2  
   -node_modules  
   -package.json  
   -requirements.txt  
   -static  
   -venv  
   -webpack.config.js  

I have python 2.7 environment for beanstalk and the same for my virtual environment. I have all the needed packages in pip list and requirements.txt. My WSGI path in the yml file from eb config is set to /myapp/application.py. The exact error I get from eb logs is:

mod_wsgi (pid=2330): Target WSGI script '/opt/python/current/app/myapp/application.py' cannot be loaded as Python module.
mod_wsgi (pid=2330): Exception occurred processing WSGI script '/opt/python/current/app/myapp/application.py'.
"File "/opt/python/current/app/cloud-dev/application.py", line 3, in <module>
from flask import render_template
ImportError: No module named flask"

I keep getting a 500 error when going to the site link. Help is much appreciated!

I encountered the exact same error. What helped for me is renaming the Flask object that you run to 'application':

from flask import Flask

application = Flask(__name__)

# run the app.
if __name__ == "__main__":
    application.run()

From the Amazon EB Docs :

Using application.py as the filename and providing a callable application object (the Flask object, in this case) allows AWS Elastic Beanstalk to easily find your application's code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM