Flask uWSGI ImportError:没有名为reques的模块

2024-09-29 07:23:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用的是python2.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

我得到这个错误:

^{pr2}$

我试过pip install -U Werkzeug,但没用。Werkzeug文档说:

“Werkzeug至少需要Python2.6才能正常工作。如果您确实需要支持旧版本,您可以下载旧版本的Werkzeug,但我们强烈建议您不要这样做。Werkzeug目前对Python3提供了实验性支持。“

我使用的是python2.7.11,因此我不确定werkzeug为什么要使用urllib.request而不是{}。在


以下是完整的stacktrace:

*** 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 ***

Tags: inpyimportappislineanacondacores
1条回答
网友
1楼 · 发布于 2024-09-29 07:23:07

你的python版本似乎有什么问题。这是来自^{}的源代码。如果您有python2.x,第一个import应该可以工作,第二个应该可以使用python3。在

try:
    from urllib2 import parse_http_list as _parse_list_header
except ImportError:  # pragma: no cover
    from urllib.request import parse_http_list as _parse_list_header

由于某些原因,您的python版本既没有python2urllib2,也没有python3urllib。在

我不熟悉PythonPython,但可能是安装已经被搞砸了吗?在

相关问题 更多 >