简体   繁体   English

Apache mod_wsgi使用不同于python-path和WSGIPythonHome中提到的python版本

[英]Apache mod_wsgi uses different version of python than which mentioned in python-path and WSGIPythonHome

There are a lot of similar questions, but i have gone through all and none of that fixed my issue. 有很多类似的问题,但我已经完成了所有这些并没有解决我的问题。 I have configured httpd in Centos 6 to run django with mod_wsgi. 我在Centos 6中配置了httpd以使用mod_wsgi运行django。 Since dist python was version 2.6, i compiled and installed python2.7 (UCS2, shared-lib). 由于dist python是2.6版本,我编译并安装了python2.7(UCS2,shared-lib)。 Created a virtulenv with virtualenv -p /usr/local/bin/python2.7 under /var/www/uatenv /var/www/uatenv下用virtualenv -p /usr/local/bin/python2.7创建了一个/var/www/uatenv

<VirtualHost *:8080>
    Alias /static/ /var/www/uatenv/my_app/static/
    WSGIDaemonProcess rbuat python-path=/var/www/my_app/core:/var/www/uatenv/lib/python2.7/site-packages
    WSGIProcessGroup rbuat
    WSGIScriptAlias / /var/www/uatenv/my_app/core/wsgi.py
</VirtualHost>

But it the server thrown 500 error and it was using a different version of python To get more details i added a couple of lines in wsgi.py as below 但它服务器抛出500错误,它使用不同版本的python为了获得更多细节,我在wsgi.py添加了几行,如下所示

import sys
print sys.version
print sys.executable
print sys.maxunicode
print sys.prefix

After restarting the server got the below details from logs 重新启动服务器后从日志中获取以下详细信息

[notice] Apache/2.2.15 (Unix) DAV/2 mod_wsgi/4.4.21 Python/2.7.10 mod_perl/2.0.4 Perl/v5.10.1 configured -- resuming normal operations
[error] 2.7.10 (default, Dec 29 2015, 07:15:09)
[error] [GCC 4.4.7 20120313 (Red Hat 4.4.7-16)]
[error] /usr/bin/python
[error] 1114111
[error] /usr/local
[error] [client 10.3.35.113] mod_wsgi (pid=7118): Target WSGI script '/var/www/uatenv/my_app/core/wsgi.py' cannot be loaded as Python module.
[error] [client 10.3.35.113] mod_wsgi (pid=7118): Exception occurred processing WSGI script '/var/www/uatenv/my_app/core/wsgi.py'.
[error] [client 10.3.35.113] Traceback (most recent call last):
[error] [client 10.3.35.113]   File "/var/www/uatenv/my_app/core/wsgi.py", line 17, in <module>
[error] [client 10.3.35.113]     from django.core.wsgi import get_wsgi_application
[error] [client 10.3.35.113]   File "/var/www/uatenv/lib/python2.7/site-packages/django/__init__.py", line 1, in <module>
[error] [client 10.3.35.113]     from django.utils.version import get_version
[error] [client 10.3.35.113]   File "/var/www/uatenv/lib/python2.7/site-packages/django/utils/version.py", line 5, in <module>
[error] [client 10.3.35.113]     import subprocess
[error] [client 10.3.35.113]   File "/usr/local/lib/python2.7/subprocess.py", line 430, in <module>
[error] [client 10.3.35.113]     import pickle
[error] [client 10.3.35.113]   File "/usr/local/lib/python2.7/pickle.py", line 34, in <module>
[error] [client 10.3.35.113]     import struct
[error] [client 10.3.35.113]   File "/usr/local/lib/python2.7/struct.py", line 1, in <module>
[error] [client 10.3.35.113]     from _struct import *
[error] [client 10.3.35.113] ImportError: /usr/local/lib/python2.7/lib-dynload/_struct.so: undefined symbol: PyUnicodeUCS2_AsEncodedString

So from the logs it is using /usr/bin/python and shows 2.7 but when i run 所以从日志中它使用/ usr / bin / python并显示2.7但是当我运行时

# /usr/bin/python
Python 2.6.6 (r266:84292, Jul 23 2015, 15:22:56)

My Questions are: 我的问题是:

  1. Why is it not using the python i given in wsgi config? 为什么不使用我在wsgi配置中给出的python?
  2. If it is using /usr/bin/python, then why is it showing as 2.7? 如果是使用/ usr / bin / python,那为什么它显示为2.7?
  3. How can i get my server running with python 2.7? 如何让我的服务器运行python 2.7?

1) check 1)检查

site.addsitedir('/var/www/uatenv/lib/python2.7/site-packages')

line exists or doesn't point to another path in your /var/www/uatenv/my_app/core/ wsgi.py file. line存在或未指向/ var / www / uatenv / my_app / core / wsgi.py文件中的另一个路径。

2) /usr/bin/python is a link file 2) / usr / bin / python是一个链接文件

3) 3)

sudo mv /usr/bin/python /root/python.backup  

This makes a backup of python file under root directory.Then : 这使得根目录下的python文件备份。然后:

sudo ln -s /usr/bin/python2.7 /usr/bin/python

Sounds like your issue might be related to how you compiled your new version of Python. 听起来您的问题可能与您编译新版Python的方式有关。 Did you compile with --enable-shared ? 你用--enable-shared编译了吗? I forget exactly why it happens, but when you don't include that flag, your system still uses the default. 我忘了它为什么会发生,但是当你不包含那个标志时,你的系统仍然使用默认值。

And then when you do include that flag, you're likely to run into a couple more problems, but these answers should help: 然后当你确实包含那个标志时,你可能会遇到更多问题,但这些答案应该会有所帮助:

Basically, the commands I use are: 基本上,我使用的命令是:

sudo ./configure --enable-shared --prefix=/install/python/here LDFLAGS=-Wl,-rpath=/install/python/here/lib
sudo make
sudo make altinstall

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM