我在Debian中为Django设置了Apache2和mod_wsgi,但是我发现了问题。 首先,这些是我的目录:
/webapps/lib/python2.6/site-packages # python eggs /webapps/lib/python2.6/ # python libraries /webapps/myproject.wsgi # wsgi script /webapps/myproject/ # django project
这是目录/webapps/lib/python2.6
(权限是777):
. ├── django │ ├── bin │ ├── conf │ ├── ... │ └── views └── site-packages ├── easy-install.pth ├── mongoengine-0.5.3-py2.6.egg ├── pymongo-2.1-py2.6-linux-x86_64.egg └── site.py
在httpd.conf
我有这样的:
WSGIScriptAlias / /webapps/myproject.wsgi WSGIPythonEggs /webapps/lib/python2.6/site-packages/
最后在myproject.wsgi
:
import sys sys.path.insert(0, '/webapps/lib/python2.6/site-packages') sys.path.insert(0, '/webapps/lib/python2.6') sys.path.insert(0, '/webapps/myproject') .. Nothing important # I tried 2 lines above as well, but nothing #import os #os.environ["PYTHON_EGG_CACHE"] = "/webapps/lib/python2.6/site-packages" from django.core.handlers.wsgi import WSGIHandler application = WSGIHandler() # This for trying if system reads eggs try: import mongoengine except Exception as e: raise ImportError(str(e) + ". " + str(sys.path))
当我重新启动Apache,并尝试访问任何网页,我得到错误500,这在日志中:
[Wed Jan 04 18:18:12 2012] [error] [client 217.217.164.22] ImportError:没有名为mongoengine的模块。 ['/ webapps / myproject','/webapps/lib/python2.6','/webapps/lib/python2.6/site-packages','/usr/lib/python2.6','/ usr / lib /python2.6/plat-linux2','/usr/lib/python2.6/lib-tk','/usr/lib/python2.6/lib-old','/usr/lib/python2.6/ lib-dynload','/usr/local/lib/python2.6/dist-packages','/usr/lib/python2.6/dist-packages','/usr/lib/pymodules/python2.6']
所以你可以看到djangoimport很好,但是没有一个是import的。 但是我没有find任何其他方式来导入它们。 为什么鸡蛋不被input?
谢谢。
我刚刚find解决scheme。 一切都是完美的,即使我重新启动了Apache,却一直在抛出同样的错误。 由于Apache运行的过程很多,关键是做一个killall httpd
,然后再次启动服务。 某些caching或进程存在错误的数据,因此无法正常运行。