首先,我要指出使用flask run
可以正常工作。另请注意,Ubuntu 16.04和macOS 10.12.4上的行为是相同的。我在macOS上使用Python 3.6.0 virtualenv,在Ubuntu上使用3.5.2。
我有以下Flask应用程序结构:
tsint/
__init__.py
app.py
wsgi.py
...
__init__.py
:
from flask import Flask
gApp = Flask(__name__)
# Config
gApp.config.from_envvar('TSINT_CONFIG')
#
# DB
#
gDB = SQLAlchemy(gApp)
#
# Import the views.
#
import tsint.app
import tsint.admin
app.py
是主要的Flask路线等,并定义了Flask用户
数据存储和安全性。
wsgi.py
:
from tsint import gApp
if __name__ == "__main__":
gApp.run()
当我尝试测试wsgi
时,我得到了“没有名为' flask'”的模块:
$ cd <directory containing tsint above>
$ uwsgi --socket 0.0.0.0:5000 --protocol=http -w tsint
*** Starting uWSGI 2.0.14 (64bit) on [Wed May 10 19:57:59 2017] ***
compiled with version: 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1) on 15 March 2017 15:31:30
os: Darwin-16.5.0 Darwin Kernel Version 16.5.0: Fri Mar 3 16:52:33 PST 2017; root:xnu-3789.51.2~3/RELEASE_X86_64
nodename: EclipseSSD.local
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 8
current working directory: /Users/rmann/Projects/Fiber/SignupApp
detected binary path: /Users/rmann/Projects/Fiber/SignupApp/venv/bin/uwsgi
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 709
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: OSX spinlocks
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to TCP address 0.0.0.0:5000 fd 3
Python version: 3.6.0 (default, Mar 9 2017, 14:47:47) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x7fe77e000000
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72752 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
Traceback (most recent call last):
File "./tsint/__init__.py", line 1, in <module>
from flask import Flask
ModuleNotFoundError: No module named 'flask'
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 26305, cores: 1)
我在virtualenv中运行,其中包含所有模块。我在猜wsgi
我不知道那些?我不清楚我错过了什么。
我已经改变了一些东西,以便更好地匹配各种教程,但是 结果没有改变。
我的目录结构现在如下所示:
tsint/
requirements.txt
setup.py
wsgi.py
env/
tsint/
__init__.py
app.py
static/
templates/
...
同样,当我运行uwsgi
时,我收到此错误:
(env) tsint/ (master)$ uwsgi --socket 127.0.0.1:8080 --protocol=http -w wsgi
*** Starting uWSGI 2.0.15 (64bit) on [Thu May 11 17:06:43 2017] ***
...
current working directory: /Path/to/tsint
detected binary path: /Path/to/tsint/env/bin/uwsgi
*** WARNING: you are running uWSGI without its master process manager ***
...
*** Operational MODE: single process ***
Traceback (most recent call last):
File "./wsgi.py", line 1, in <module>
from tsint import gApp
File "./tsint/__init__.py", line 1, in <module>
from flask import Flask
ModuleNotFoundError: No module named 'flask'
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 36939, cores: 1)
同样,似乎uwsgi无法找到像flask
这样的已安装模块。我见过
谈论-H
选项以指出virtualenv,但这会导致其他问题
对我来说,没有一个教程显示virtualnv&amp; uWsgi使用此选项。
谢谢!