Django、VirtualEnv、Ubuntu、uwsgi/gunicorn:无法找到所有python/Django模块

Django、VirtualEnv、Ubuntu、uwsgi/gunicorn:无法找到所有python/Django模块,python,django,ubuntu,uwsgi,pythonpath,Python,Django,Ubuntu,Uwsgi,Pythonpath,我试图设置uWSGI来为我的django应用程序服务,但我的路径有问题,或者至少我认为这是一个路径问题。症状是,当我向应用程序发出一个curl请求时,我得到了一个回溯,表明找不到基本的python/django模块。例: File "/opt/example/venvs/example/lib/python2.7/site-packages/django/test/_doctest.py", line 104, in <module> import unittest, difflib

我试图设置uWSGI来为我的django应用程序服务,但我的路径有问题,或者至少我认为这是一个路径问题。症状是,当我向应用程序发出一个curl请求时,我得到了一个回溯,表明找不到基本的python/django模块。例:

File "/opt/example/venvs/example/lib/python2.7/site-packages/django/test/_doctest.py", line 104, in <module> import unittest, difflib, pdb, tempfile
File "/usr/lib/python2.7/pdb.py", line 59, in <module>
class Pdb(bdb.Bdb, cmd.Cmd): AttributeError: 'module' object has no attribute 'Cmd'
除了我为调试添加的打印路径外,.wsgi文件是相当标准的:

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.settings")

import sys
print sys.path

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
以下是uwsgi ini文件,请注意我必须添加的所有pythonpath:

[uwsgi]
#socket=/tmp/hs.com.sock
virtualenv=/opt/example/venv
chdir=/opt/example/apps/example/src
module=example.wsgi:application
master=true
workers=8
pidfile=/opt/example/apps/example/src/example/uwsgi-master.pid
max-requests=5000
#plugins=python
enable-threads=true
processes=2
no-site=true
http=:8003
#env=DJANGO_SETTINGS_MODULE=example.settings
pythonpath=..
pythonpath=/vagrant/src
pythonpath=/opt/example/apps/example/src/example
pythonpath=/opt/example/venvs/example/lib/python2.7
pythonpath=/opt/example/venvs/example/lib/python2.7/plat-linux2
pythonpath=/opt/example/venvs/example/lib/python2.7/lib-tk
pythonpath=/opt/example/venvs/example/lib/python2.7/lib-old
pythonpath=/opt/example/venvs/example/lib/python2.7/lib-dynload
pythonpath=/opt/example/venvs/example/lib/python2.7/distutils
#pythonpath=/opt/example/venvs/example/lib/python2.7/encodings
#pythonpath=/opt/example/venvs/example/lib/python2.7/config
pythonpath=/usr/lib/python2.7/
pythonpath=/usr/lib/python2.7/lib-dynload/
pythonpath=/usr/lib/python2.7/distutils/
pythonpath=/usr/lib/python2.7/plat-linux2/
pythonpath=/usr/lib/python2.7/lib-tk/
#pythonpath=/opt/example/venvs/example/lib/python2.7/site-packages/django/
#pythonpath=/opt/example/venvs/example/lib/python2.7/site-packages/django/core/
pythonpath=/opt/example/venvs/example/lib/python2.7/site-packages/django/core/management
#pythonpath=/opt/example/venvs/example/lib/python2.7/site-packages/django/core/management/commands
pythonpath=/opt/example/venvs/example/local/lib/python2.7/site-packages
pythonpath=/opt/example/venvs/example/lib/python2.7
pythonpath=/opt/example/venvs/example/lib/python2.7/site-packages
pythonpath=/vagrant/src/example
之所以有这么多pythonpath,是因为应用程序找不到非常基本的模块,所以我一直在添加路径来解决它。这对几个错误有效,但1我找不到上面的Cmd AttributeError的正确路径,2添加每个单独的路径感觉不太对

uwsgi输出到“uwsgi-ini文件”

[uWSGI] getting INI configuration from xxx
*** Starting uWSGI 1.9.15 (32bit) on [Fri Sep 13 18:12:44 2013] ***
compiled with version: 4.6.3 on 13 September 2013 06:46:44
os: Linux-3.2.0-23-generic-pae #36-Ubuntu SMP Tue Apr 10 22:19:09 UTC 2012
nodename: xxx
machine: i686
clock source: unix
detected number of CPU cores: 1
current working directory: /vagrant/src
writing pidfile to /opt/example/apps/example/src/example/uwsgi-master.pid
detected binary path: /opt/example/venvs/example/bin/uwsgi
your processes number limit is 1824
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
uWSGI http bound on localhost:8003 fd 4
uwsgi socket 0 bound to TCP address 127.0.0.1:34622 (port auto-assigned) fd 3
Python version: 2.7.3 (default, Apr 10 2013, 06:03:17)  [GCC 4.6.3]
Set PythonHome to /opt/example/venv
Python main interpreter initialized at 0xa044e58
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 192012 bytes (187 KB) for 2 cores
*** Operational MODE: preforking ***
added ../ to pythonpath.
added /vagrant/src/ to pythonpath.
added /opt/example/apps/example/src/example/ to pythonpath.
added /opt/example/venvs/example/lib/python2.7/ to pythonpath.
added /opt/example/venvs/example/lib/python2.7/plat-linux2 to pythonpath.
added /opt/example/venvs/example/lib/python2.7/lib-tk to pythonpath.
added /opt/example/venvs/example/lib/python2.7/lib-old to pythonpath.
added /opt/example/venvs/example/lib/python2.7/lib-dynload/ to pythonpath.
added /opt/example/venvs/example/lib/python2.7/distutils/ to pythonpath.
added /usr/lib/python2.7/ to pythonpath.
added /usr/lib/python2.7/lib-dynload/ to pythonpath.
added /usr/lib/python2.7/distutils/ to pythonpath.
added /usr/lib/python2.7/plat-linux2/ to pythonpath.
added /usr/lib/python2.7/lib-tk/ to pythonpath.
added /opt/example/venvs/example/lib/python2.7/site-packages/django/core/management/ to pythonpath.
added /opt/example/venvs/example/local/lib/python2.7/site-packages/ to pythonpath.
added /opt/example/venvs/example/lib/python2.7/ to pythonpath.
added /opt/example/venvs/example/lib/python2.7/site-packages/ to pythonpath.
added /vagrant/src/example/ to pythonpath.
['/vagrant/src/example/', '/opt/example/venvs/example/lib/python2.7/site-packages/', '/opt/example/venvs/example/lib/python2.7/', '/opt/example/venvs/example/local/lib/python2.7/site-packages/', '/opt/example/venvs/example/lib/python2.7/site-packages/django/core/management/', '/usr/lib/python2.7/lib-tk/', '/usr/lib/python2.7/plat-linux2/', '/usr/lib/python2.7/distutils/', '/usr/lib/python2.7/lib-dynload/', '/usr/lib/python2.7/', '/opt/example/venvs/example/lib/python2.7/distutils/', '/opt/example/venvs/example/lib/python2.7/lib-dynload/', '/opt/example/venvs/example/lib/python2.7/lib-old', '/opt/example/venvs/example/lib/python2.7/lib-tk', '/opt/example/venvs/example/lib/python2.7/plat-linux2', '/opt/example/venvs/example/lib/python2.7/', '/opt/example/apps/example/src/example/', '/vagrant/src/', '../', '.', '', '/opt/example/venv/lib/python2.7/', '/opt/example/venv/lib/python2.7/plat-linux2', '/opt/example/venv/lib/python2.7/lib-tk', '/opt/example/venv/lib/python2.7/lib-old', '/opt/example/venv/lib/python2.7/lib-dynload', '/vagrant/src/example']
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0xa044e58 pid: 2911 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 2911)
spawned uWSGI worker 1 (pid: 2912, cores: 1)
spawned uWSGI worker 2 (pid: 2913, cores: 1)
spawned uWSGI http 1 (pid: 2914)
从另一个终端运行curl-v localhost:8003,我得到了上面发布的“AttributeError…”。旋度输出为:

curl: (52) Empty reply from server
* Closing connection #0
以下是我尝试过的:

使用最新的uWSGI版本1.9.15和LTS版本1.4.x 在virtualenv内部和外部安装uWSGI django的runserver可以很好地为我的应用程序服务,我可以看到打印出来的路径,因为wsgi文件中有debug print sys.path语句,它只是我在wsgi.ini文件中拥有的路径的子集 还从wsgi.py文件中打印出runserver和uwsgi环境中的环境变量,我看不到任何重要的不同之处 uwsgi能够提供基本的test.py应用程序文件而不会出现问题,因此我认为这消除了任何安装/设置问题 试着用sudo运行uwsgi 我还使用直接从startproject创建的基本django应用程序进行了尝试,但同样的attributeerror失败,并且需要相同的Python路径列表

我一定缺少一些简单的设置或配置?如果需要更多信息,请告诉我


Edit1:这看起来并不特定于uWSGI,而是与virtualenv设置和路径更相关。我安装了gunicorn,得到了完全相同的结果

我认为您的uwsgi.ini文件在

virtualenv=/opt/example/venv
virtualenv=/opt/example/venv