2

好的,所以我在没有virtualenv的情况下尝试了这个:

uwsgi --home /home/auston/new_proj/ --socket /tmp/uwsgi2.sock --chmod-socket --module app_wsgi --pp /home/auston/new_proj/nikeshere --logto /tmp/uwsgi.log --master --processes 4 -P

几乎无论如何,我明白了:

*** Starting uWSGI 0.9.6.5 (32bit) on [Thu Oct 21 08:05:44 2010] ***
compiled with version: 4.4.3
Python version: 2.6.6 (r266:84292, Oct 21 2010, 04:07:38)
[GCC 4.4.3]
your memory page size is 4096 bytes
allocated 412 bytes (0 KB) for 1 request's buffer.
Setting PythonHome to /home/auston/new_proj/...
binding on UNIX socket: /tmp/uwsgi2.sock
chmod() socket to 666 for lazy and brave users
your server socket listen backlog is limited to 64 connections
added /home/auston/new_proj/nikeshere to pythonpath.
initializing hooks...done.
['/home/auston/new_proj/nikeshere', '.', '', '/home/auston/new_proj/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg', '/home/auston/new_proj/lib/python2.6/site-packages/pip-0.8.1-py2.6.egg', '/home/auston/new_proj/lib/python26.zip', '/home/auston/new_proj/lib/python2.6', '/home/auston/new_proj/lib/python2.6/plat-linux2', '/home/auston/new_proj/lib/python2.6/lib-tk', '/home/auston/new_proj/lib/python2.6/lib-old', '/home/auston/new_proj/lib/python2.6/lib-dynload', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/home/auston/new_proj/lib/python2.6/site-packages', '/usr/local/lib/python2.6/dist-packages/pip-0.8.1-py2.6.egg', '/usr/local/lib/python2.6/site-packages', '/usr/local/lib/python2.6/dist-packages', '/usr/lib/python2.6/dist-packages', '/home/auston/new_proj/nikeshere', '/usr/local/lib/python2.6']
Traceback (most recent call last):
  File "/home/auston/new_proj/nikeshere/app_wsgi.py", line 11, in <module>
    import django.core.handlers.wsgi
  File "/usr/local/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line 1, in <module>
    from threading import Lock
  File "/usr/lib/python2.6/threading.py", line 13, in <module>
    from functools import wraps
  File "/usr/lib/python2.6/functools.py", line 10, in <module>
    from _functools import partial, reduce
ImportError: No module named _functools

如果我将 --home 更改为 /usr/local/lib/python/2.6 我在 app_wsgi.py 导入 o​​s 时会失败。这是,下面,以防万一:

import sys
import os

sys.path.append(os.path.abspath(os.path.dirname(__file__)))

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

本质上我在问,我怎样才能让 uWSGI 识别 functools 或走上正确的路径(路径在上面的输出中)。我将不胜感激你们可以提供的任何帮助!

PS Ubuntu 10.04 - uWSGI 0.9.6.5 - NGINX 0.8.53 - 虚拟环境 Python 2.6.5 - “常规(或系统)” Python 2.6.6 - Django 1.2.3

更新:

如果我像这样省略“--module”,我可以让 uwsgi 开始接受请求:

uwsgi --home /home/auston/new_proj --socket /tmp/uwsgi2.sock --chmod-socket --pp /home/auston/new_proj/nikeshere --logto /tmp/uwsgi.log --master --processes 4 -P

但现在我收到一个未找到应用程序的错误:

“未找到 uWSGI 错误 wsgi 应用程序”

我离得更近了,但我仍然会感谢建议,因为找不到该应用程序,因为我无法包含加载它所需的模块!

4

4 回答 4

1

如上所述,问题出在 pythonpath 并且无法找到名为 _functools 的模块。

显然,_functools 是 ac 模块,我需要将它的路径附加到 pythonpath 以便找到它,因此与原始 wsgi.py 的区别现在是:

import sys
sys.path.append('/usr/local/lib/python2.6/lib-dynload') # to load _functools
sys.path.append('/usr/local/lib/python2.6/site-packages') # to load django
sys.path.append('/usr/local/lib/python2.6/dist-packages') # cautionary to load django
sys.path.append('/usr/lib/python2.6') # to load os
import os

os.environ['DJANGO_SETTINGS_MODULE'] = 'iwin.settings'

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

非常hacky,但它现在有效......

于 2010-10-21T20:48:22.520 回答
1

我知道这是旧主题并且堆栈构建块的版本发生了变化,但是我遇到了同样的问题,即在 uWSGi 下无法识别 virtualenv 中安装的库。解决方案是将 home 参数指向 virtualenv,如下所示(取自https://uwsgi.readthedocs.org/en/latest/tutorials/Django_and_nginx.html)。

所以对我来说命令:

uwsgi --http :8000 --module ii.wsgi --home /home/dev/.virtualenvs/ii_env/

工作,同时在 django 应用程序 (ii) 目录中。

# mysite_uwsgi.ini file
[uwsgi]

# Django-related settings
# the base directory (full path)
chdir           = /path/to/your/project
# Django's wsgi file
module          = project.wsgi
# the virtualenv (full path)
home            = /path/to/virtualenv

# process-related settings
# master
master          = true
# maximum number of worker processes
processes       = 10
# the socket (use the full path to be safe
socket          = /path/to/your/project/mysite.sock
# ... with appropriate permissions - may be needed
# chmod-socket    = 664
# clear environment on exit
vacuum          = true
于 2014-03-11T15:00:10.633 回答
0

查看http://blog.zacharyvoase.com/2010/03/05/django-uwsgi-nginx/。他正在使用非常相似的设置。

于 2010-10-21T11:49:41.377 回答
0

我一直有非常相似的问题,我发现了这个:

当您安装 deverelenv 时,它会通过创建指向原始标准库的符号链接来“安装”Python 标准库(例如 /usr/lib/python2.7)。但是当您检查您的 virtualenv Python lib 目录时,只会为几个基本库创建符号链接。您的 functools 可能不在其中。

所以解决方案是手动创建符号链接。这是一个 PITA,因为您可能需要创建很多符号链接,但对我来说这似乎是一个更清洁的解决方案。您不必破解任何源文件,而且它是透明的。

符号链接不应该在 的根目录中创建venv_directory,而是在例如

venv_directory/lib/python2.7/site-packages/

希望对你有帮助!

于 2012-02-24T11:28:46.167 回答