3

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. Since dist python was version 2.6, i compiled and installed python2.7 (UCS2, shared-lib). Created a virtulenv with virtualenv -p /usr/local/bin/python2.7 under /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

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
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?
  2. If it is using /usr/bin/python, then why is it showing as 2.7?
  3. How can i get my server running with python 2.7?
1
  • How did you install mod_wsgi? If you installed it from the centos repo it's probably compiled against python2.6 and incompatible with python2.7. You'll also need to compile mod_wsgi yourself. Commented Sep 1, 2016 at 17:44

2 Answers 2

0

1) check

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.

2) /usr/bin/python is a link file

3)

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

This makes a backup of python file under root directory.Then :

sudo ln -s /usr/bin/python2.7 /usr/bin/python
Sign up to request clarification or add additional context in comments.

6 Comments

I didn't get it. Can you please explain?
in your "wsgi.py" file is there a line that i tell you in code block? Or does it adresses your python 2.6 path?
Nope. I don't have that line in the wsgi.py, I have configured a WSGI python path in the apache config under virtualhosts which points to python 2.7 code block.
please add then and inform us about the result, it could be the answer of "Why is it not using the python i given in wsgi config?"
I did it, but didn't help and I already have this path in my Python path.
|
0

Sounds like your issue might be related to how you compiled your new version of Python. Did you compile with --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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.