【发布时间】:2016-06-05 22:00:32
【问题描述】:
我正在使用 Python 2.7.11 :: Anaconda 2.4.0 (x86_64)
我正在努力学习uWSGI。我可以从本教程开始获得“Hello World”PythonuWSGI 应用程序:http://uwsgi-docs.readthedocs.io/en/latest/WSGIquickstart.html#the-first-wsgi-application
现在我想制作一个“Hello World”Flask 应用程序。当我跑步时:
uwsgi --socket 127.0.0.1:3031 --wsgi-file app.py --callable app --processes 4 --threads 2 --stats 127.0.0.1:9191
我收到此错误:
File "/Users/JohnsMacBook/anaconda/lib/python2.7/site-packages/werkzeug/http.py", line 28, in <module>
from urllib.request import parse_http_list as _parse_list_header
ImportError: No module named request
我尝试了pip install -U Werkzeug,但没有奏效。 Werkzeug 文档说:
“Werkzeug 至少需要 Python 2.6 才能正常工作。如果您确实需要支持旧版本,您可以下载旧版本的 Werkzeug,但我们强烈建议不要这样做。Werkzeug 目前对 Python 3 有实验性支持。 "
我使用的是 Python 2.7.11,所以我不确定为什么 werkzeug 尝试使用 urllib.request 而不是 urllib2。
这是完整的堆栈跟踪:
*** Starting uWSGI 2.0.13.1 (64bit) on [Sun Jun 5 17:31:43 2016] ***
compiled with version: 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31) on 05 June 2016 16:36:34
os: Darwin-15.3.0 Darwin Kernel Version 15.3.0: Thu Dec 10 18:40:58 PST 2015; root:xnu-3248.30.4~1/RELEASE_X86_64
nodename: Johns-MacBook-Pro.local
machine: x86_64
clock source: unix
detected number of CPU cores: 8
current working directory: /Users/JohnsMacBook/Dropbox/DEV/PyDev/flask-nginx
detected binary path: /Users/JohnsMacBook/anaconda/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
your processes number limit is 709
your memory page size is 4096 bytes
detected max file descriptor number: 256
lock engine: OSX spinlocks
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to TCP address 127.0.0.1:3031 fd 3
Python version: 2.7.10 (default, Oct 23 2015, 18:05:06) [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)]
Python main interpreter initialized at 0x7f8531c09740
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 415200 bytes (405 KB) for 8 cores
*** Operational MODE: preforking+threaded ***
Traceback (most recent call last):
File "app.py", line 1, in <module>
from flask import Flask
File "/Users/JohnsMacBook/anaconda/lib/python2.7/site-packages/flask/__init__.py", line 17, in <module>
from werkzeug.exceptions import abort
File "/Users/JohnsMacBook/anaconda/lib/python2.7/site-packages/werkzeug/__init__.py", line 154, in <module>
__import__('werkzeug.exceptions')
File "/Users/JohnsMacBook/anaconda/lib/python2.7/site-packages/werkzeug/exceptions.py", line 71, in <module>
from werkzeug.wrappers import Response
File "/Users/JohnsMacBook/anaconda/lib/python2.7/site-packages/werkzeug/wrappers.py", line 26, in <module>
from werkzeug.http import HTTP_STATUS_CODES, \
File "/Users/JohnsMacBook/anaconda/lib/python2.7/site-packages/werkzeug/http.py", line 28, in <module>
from urllib.request import parse_http_list as _parse_list_header
ImportError: No module named request
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 master process (pid: 9870)
spawned uWSGI worker 1 (pid: 9871, cores: 2)
spawned uWSGI worker 2 (pid: 9872, cores: 2)
spawned uWSGI worker 3 (pid: 9873, cores: 2)
spawned uWSGI worker 4 (pid: 9874, cores: 2)
*** Stats server enabled on 127.0.0.1:9191 fd: 15 ***
【问题讨论】:
-
也许你可以给我们看一些代码?发布一个可验证的例子?而不是将我们指向教程。谢谢
-
运行
pip -V以检查您使用的python 和pip 版本。我相信urllib.request只存在于 python 3 中。所以这里似乎有些混乱。如果您的版本错误,您可能需要卸载一些 pip 包并重新安装它们。 -
你的回溯说
Python version: 2.7.10,但在其他地方你说python 2.7.11。好像哪里搞混了?
标签: python flask uwsgi werkzeug