python encodings模块,mod_wsgi:ImportError:没有名为'encodings'的模块

I'm using Apache 2.2.15 on CentOS 6.5. I'm trying to set up a Django app using mod_wsgi.

I'm using a virtual environment, and mod_wsgi was configured with --with-python=/path/to/virtualenv/bin/python3.4.

I've added this to my httpd.conf:

WSGIPythonPath /srv/myproject:/path/to/virtualenv/lib/python3.4/site-packages

WSGIPythonHome /path/to/virtualenv

WSGIScriptAlias / /srv/myproject/myproject/wsgi.py

...

In wsgi.py, I added

sys.path.insert(1, "/path/to/virtualenv/lib/python3.4/site-packages")

The problem is that when I try to open the app in my browser, it loads indefinitely. Here's the Apache error log:

Fatal Python error: Py_Initialize: Unable to get the locale encoding

ImportError: No module named 'encodings'

[Mon Jun 30 17:37:28 2014] [notice] child pid 19370 exit signal Aborted (6)

[Mon Jun 30 17:37:28 2014] [notice] child pid 19371 exit signal Aborted (6)

...

[Mon Jun 30 17:37:28 2014] [notice] child pid 19377 exit signal Aborted (6)

Fatal Python error: Py_Initialize: Unable to get the locale encoding

ImportError: No module named 'encodings'

What's interesting is that in both the system installation of Python (2.6) and the virtual environment version (3.4), import encodings works fine! I've tried using the example WSGI script from the mod_wsgi CheckingYourInstallation page to confirm which version of Python is being used by Apache, but I get the same ImportError.

Does anyone have a suggestion for next steps? I've scoured the docs but I don't know where to go from here.

解决方案

So with some help with my friends (IE: SysAdmins), we got this figured out last night. I learn best by example, so let's assume you're running Apache with mod_wsgi as Linux group apache with user flipperpa. Let's assume you're hosting in /home/my_project with wsgi.py in my_project/wsgi.py.

At the top level (ls -l /):

drwxr-xr-x. 47 root root 4096 Jul 9 09:43 home

In the home directory (ls -l /home):

drwxrwsr-x 7 flipper apache 4096 Jul 29 10:22 my_project

This was the key. The lower case "s" means the apache group's setgid bit is set, and the execute bit is set. The final "x", of course, means anyone can execute.

Check your permissions down the tree; this did the trick for us.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值