[英]Issue Running gunicorn to serve flask app
objective: get gunicorn to serve the flask app 目标:让Gunicorn服务于烧瓶应用
attempt: run the following command: 尝试:运行以下命令:
gunicorn [the name of my project folder]:flaskr
output: 输出:
[2019-08-26 15:04:32 +0000] [16063] [INFO] Starting gunicorn 19.9.0
[2019-08-26 15:04:32 +0000] [16063] [INFO] Listening at: http://127.0.0.1:8000 (16063)
[2019-08-26 15:04:32 +0000] [16063] [INFO] Using worker: sync
[2019-08-26 15:04:32 +0000] [16067] [INFO] Booting worker with pid: 16067
[2019-08-26 15:04:32 +0000] [16067] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 583, in spawn_worker
worker.init_process()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 129, in init_process
self.load_wsgi()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 138, in load_wsgi
self.wsgi = self.app.wsgi()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 52, in load
return self.load_wsgiapp()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/local/lib/python2.7/dist-packages/gunicorn/util.py", line 350, in import_app
__import__(module)
ImportError: No module named [the name of my project folder]
[2019-08-26 15:04:32 +0000] [16067] [INFO] Worker exiting (pid: 16067)
[2019-08-26 15:04:32 +0000] [16063] [INFO] Shutting down: Master
[2019-08-26 15:04:32 +0000] [16063] [INFO] Reason: Worker failed to boot.
I have deployed this project to my web server. 我已经将该项目部署到了我的Web服务器。 In the home directory of the account I am using to administer this webserver, I have the project folder as I was working on it from my workstation.
在我用来管理该Web服务器的帐户的主目录中,有一个项目文件夹,因为我正在从工作站上对其进行处理。 Here is the tree output ran from within the project folder:
这是从项目文件夹中运行的树输出:
├── flaskr
│ ├── auth.py
│ ├── build
│ ├── db.py
│ ├── db.pyc
│ ├── dist
│ ├── flaskr.egg-info
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── MANIFEST.in
│ ├── old
│ ├── __pycache__
│ ├── schema.sql
│ ├── setup.py
│ ├── static
│ └── templates
├── instance
│ └── flaskr.sqlite
├── keys.csv
├── tests
├── venv
│ ├── bin
│ ├── include
│ ├── lib
│ ├── lib64
│ ├── pyvenv.cfg
│ └── share
└── venv.sh
I have installed gunicorn in the venv. 我已将Venicorn安装在静脉内。 I also exported the environment variables as shown in the flask tutorial.
我还导出了烧瓶教程中所示的环境变量。
I have also configured manifest.ini and setup.py to make the program installable. 我还配置了manifest.ini和setup.py以使程序可安装。 I have attempted to install by running the following from within the project folder:
我试图通过在项目文件夹中运行以下命令进行安装:
pip install -e
I get the following output: 我得到以下输出:
Usage:
pip install [options] <requirement specifier> [package-index-options] ...
pip install [options] -r <requirements file> [package-index-options] ...
pip install [options] [-e] <vcs project url> ...
pip install [options] [-e] <local project path> ...
pip install [options] <archive url/path> ...
-e option requires an argument
I have verified that the app itself is running on my workstation after using "flask run". 我已验证使用“ flask run”后,应用程序本身已在我的工作站上运行。
If you need code for any of the files, please let me know and the best way to share. 如果您需要任何文件的代码,请告诉我以及最佳共享方式。 Here is some code that I think it relevant for now:
这是一些我认为目前相关的代码:
setup.py: setup.py:
from setuptools import find_packages, setup
setup(
name='flaskr',
version='1.0.0',
packages=find_packages(),
include_package_data=True,
zip_safe=False,
install_requires=[
'flask',
],
)
manifest.in: manifest.in:
include flaskr/schema.sql
graft flaskr/static
graft flaskr/templates
global-exclude *.pyc
EDIT: 8/26/19 - 1:30 pm: 编辑:19/8/26-下午1:30:
I have attempted to discover the cause of this issue by following another article, https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-gunicorn-and-nginx-on-ubuntu-14-04 When I run this command: 我试图通过关注另一篇文章https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-gunicorn-and-nginx-on-ubuntu来发现此问题的原因-14-04当我运行此命令时:
gunicorn --bind 0.0.0.0:8000 wsgi
output: 输出:
[2019-08-26 17:23:14 +0000] [17748] [INFO] Starting gunicorn 19.9.0
[2019-08-26 17:23:14 +0000] [17748] [INFO] Listening at: http://0.0.0.0:8000 (17748)
[2019-08-26 17:23:14 +0000] [17748] [INFO] Using worker: sync
[2019-08-26 17:23:14 +0000] [17752] [INFO] Booting worker with pid: 17752
[2019-08-26 17:23:15 +0000] [17752] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 583, in spawn_worker
worker.init_process()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 129, in init_process
self.load_wsgi()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 138, in load_wsgi
self.wsgi = self.app.wsgi()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 52, in load
return self.load_wsgiapp()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/local/lib/python2.7/dist-packages/gunicorn/util.py", line 350, in import_app
__import__(module)
File "/home/[my user name]/[name of the project folder]/wsgi.py", line 1, in <module>
from [name of the project folder] import app
ImportError: No module named [name of the project folder]
[2019-08-26 17:23:15 +0000] [17752] [INFO] Worker exiting (pid: 17752)
[2019-08-26 17:23:15 +0000] [17748] [INFO] Shutting down: Master
[2019-08-26 17:23:15 +0000] [17748] [INFO] Reason: Worker failed to boot.
Here is the wsgi.py: 这是wsgi.py:
from [the name of my project folder] import app
if __name__ == "__main__":
app.run()
I suspect I am naming the wrong thing in my wsgi.py 我怀疑我在wsgi.py中命名错误的内容
Try inserting your project's paths to sys.path
before attempting to import your application instance. 在尝试导入应用程序实例之前,请尝试将项目的路径插入
sys.path
。
wsgi.py: wsgi.py:
import os
import sys
directory = os.path.dirname(os.path.realpath(__file__))
app_directory = os.path.join(directory, 'flaskr')
if directory not in sys.path:
sys.path.insert(0, directory)
if app_directory not in sys.path:
sys.path.insert(0, app_directory)
from flaskr import app
if __name__ == '__main__':
app.run()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.