Django 的问题mod-wsgi +心理咨询师2
所以我第一次尝试让 Django 与 mod-wsgi 一起运行。我已经按照示例中所示配置了 Apache,并且我非常确定我所做的一切都是正确的。
我没有设置 PYTHON_EGG_CACHE
变量,因此它使用默认值:/var/www/.python-eggs
。我创建了这个目录并使其可供用户 www-data
写入。
当我打开网站时,它显示 500.html
模板的输出,这是我在日志中得到的内容:
...
File "/usr/local/.../parts/django/django/db/__init__.py", line 17, in load_backend
return import_module('.base', 'django.db.backends.%s' % backend_name)
File "/usr/local/.../parts/django/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/usr/local/.../parts/django/django/db/backends/postgresql_psycopg2/base.py", line 22, in <module>
raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
ImproperlyConfigured: Error loading psycopg2 module: cannot import name tz
这是我在 /var/www/.python-eggs/
中的内容>
# ls -la /var/www/.python-eggs/
total 12
drwxr-xr-x 3 www-data www-data 4096 Jan 27 04:19 .
drwxr-xr-x 5 root root 4096 Jan 27 04:18 ..
drwxr-xr-x 3 www-data www-data 4096 Jan 27 04:19 psycopg2-2.0.13-py2.5-linux-i686.egg-tmp
# ls -la /var/www/.python-eggs/psycopg2-2.0.13-py2.5-linux-i686.egg-tmp/psycopg2/
total 368
drwxr-xr-x 2 www-data www-data 4096 Jan 27 04:19 .
drwxr-xr-x 3 www-data www-data 4096 Jan 27 04:19 ..
-rwxr-xr-x 1 www-data www-data 363318 Jan 22 03:44 _psycopg.so
psycopg2 Egg 目录中唯一的文件是_psycopg.so
。没有 tz.py 文件,我认为这就是问题所在。
请指教。
PS,我使用 buildout 和 djangorecipe 来部署 Django。我使用 buildout
用户运行构建脚本。但不确定这是否有意义。
PPS、psycopg2
已正确安装,因为我能够运行 syncdb
。
So I am trying to make Django running with mod-wsgi for the first time. I have configured Apache as shown in examples and I am pretty sure I did everything right.
I did not set the PYTHON_EGG_CACHE
variable so it uses the default: /var/www/.python-eggs
. I have created this directory and made it writeable for user www-data
.
When I open the site it shows the output from 500.html
template and here's what I get in log:
...
File "/usr/local/.../parts/django/django/db/__init__.py", line 17, in load_backend
return import_module('.base', 'django.db.backends.%s' % backend_name)
File "/usr/local/.../parts/django/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/usr/local/.../parts/django/django/db/backends/postgresql_psycopg2/base.py", line 22, in <module>
raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
ImproperlyConfigured: Error loading psycopg2 module: cannot import name tz
Here's what I have in /var/www/.python-eggs/
# ls -la /var/www/.python-eggs/
total 12
drwxr-xr-x 3 www-data www-data 4096 Jan 27 04:19 .
drwxr-xr-x 5 root root 4096 Jan 27 04:18 ..
drwxr-xr-x 3 www-data www-data 4096 Jan 27 04:19 psycopg2-2.0.13-py2.5-linux-i686.egg-tmp
# ls -la /var/www/.python-eggs/psycopg2-2.0.13-py2.5-linux-i686.egg-tmp/psycopg2/
total 368
drwxr-xr-x 2 www-data www-data 4096 Jan 27 04:19 .
drwxr-xr-x 3 www-data www-data 4096 Jan 27 04:19 ..
-rwxr-xr-x 1 www-data www-data 363318 Jan 22 03:44 _psycopg.so
The only file in psycopg2 egg directory is _psycopg.so
. There's no tz.py
file and I think this is the problem.
Please advice.
P.S., I use buildout and djangorecipe
to deploy Django. I run buildout script with buildout
user. Not sure if it makes sense though.
P.P.S, psycopg2
is installed correctly because I am able to run syncdb
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,我已经找到解决方案了。我已经使用系统 python 进行构建,并且它已经在站点包中包含了 psycopg2。系统站点包中的 psycopg2 与 buildout 安装的 psycopg2 之间似乎存在某种冲突。我已经设置了一个虚拟 python 环境并将其用于构建。这有帮助!不再出现导入错误。
Ok, I have found the solution. I have used the system python for buildout and it already had psycopg2 in site-packages. It seems there was some kind of conflict between psycopg2 in system site-packages and the one installed by buildout. I have set up a virtual python environment and used it for buildout. And this helped! No more import errors.
我建议,如果您能够从命令行导入它,那么在路径的某个位置,www-data 用户将被禁止访问 Egg 路径。
I would suggest that if you're able to import it from the command line, then somewhere up the path, the www-data user is being forbidden access to the egg path.