2010-10-21 58 views
2

OK,所以我跟&试过这个没有的virtualenv:uWSGI + Django的+ VIRTUALENV无法拿起_functools(导入错误)

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导入失败。这,下面,以防万一:

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或得到正确的路径(path是在输出上面)。我将不胜感激任何帮助,你们可以给!

P.S. Ubuntu的10.04 - uWSGI 0.9.6.5 - NGINX 0.8.53 - 虚拟ENV的Python 2.6.5 - “常规(或系统)” 的Python 2.6.6 - 1.2.3 Django的

UPDATE:

我能够得到uwsgi开始接受申请,如果我省略“--module”像这样:

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找不到应用程序”

我更接近,但我仍然会很欣赏建议,因为找不到应用程序,因为我不能包含加载它所需的模块!

回答

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() 

非常哈克,但它的作品现在...

0

我一直有非常类似的问题,我发现这一点:

当您安装virtuelenv,它通过创建符号链接到原来的“安装” Python标准库一个(在like/u SR/LIB/python2.7)。但是当你检查你的virtualenv Python lib目录时,只有几个基本库创建了符号链接。你的functools可能不在其中。

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

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

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

希望它适合你!

1

我知道它的旧主题和堆栈构建块的版本已更改,但是我在使用virtualenv时未识别uWSGi安装的库下有同样的问题。解决方案是将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应用程序(二)目录之中。

# 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