2010-10-21 44 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