Centos 6.5 Python 3.3.x Django 1.6 Apache 2.2

1,350 views
Skip to first unread message

Guillem Liarte

unread,
May 2, 2014, 7:11:05 AM5/2/14
to django...@googlegroups.com
Hello,

I have looked through the web in several different especialised forums but I cannot find the way to do this properly.

My aim is to have an environment to host Django applications running Centos 6. So far I have managed to:

- Get Centos 6.5 + Ptython 3.3.2 + Django 1.6 (virtual env), running a test application using python's webserver. Time to move into Apache.
- I manage to get it working from Apache but instead of Python 3.3.2, it uses the Python 2.6 installed in the system. No matter if I launch apache from the virtual environment, even once I have enabled python3.

I know Djanog 1.6 can use python 2.6. But that is not what i want to achieve, as 1.7 will not.

Just to give some idea of what I have installed:



In the system:
python --version
Python 2.6.6

From RedHat SCL:
source /opt/rh/python33/enable
python --version
Python 3.3.2

Inside the virtual environment I have:

Django (1.6.3)
pip (1.4.1)
setuptools (0.9.8)

That starts successfully:

python manage.py runserver 192.168.0.16:8000


Starting development server at http://192.168.0.16:8000/                                                                                                                                      
Quit the server with CONTROL-C.

When getting to admin or any error page:

Django Version: 1.6.3
Python Version: 3.3.2

Python Path:
['/data/app/guillem-py3-dj17-test/guillem_test',
 '/data/app/guillem-py3-dj17-test/lib64/python33.zip',
 '/data/app/guillem-py3-dj17-test/lib64/python3.3',
 '/data/app/guillem-py3-dj17-test/lib64/python3.3/plat-linux',
 '/data/app/guillem-py3-dj17-test/lib64/python3.3/lib-dynload',
 '/opt/rh/python33/root/usr/lib64/python3.3',
 '/opt/rh/python33/root/usr/lib/python3.3',
 '/data/app/guillem-py3-dj17-test/lib/python3.3/site-packages']
_______________
 
When starting this from Apache 2.2 instead of the python embedded server:


httpd -k restart -e debug
...
[Fri May 02 11:53:29 2014] [debug] mod_so.c(246): loaded module wsgi_module
...

The Apache service starts in my port of choice:

tcp 0 0 192.168.0.16:8082 0.0.0.0:* LISTEN 1676/httpdWhat I get now is:

So now I get:

Django Version: 1.6
Python Executable: /data/app/guillem-py3-dj17-test/bin/python
Python Version: 2.6.6
Python Path:

['/data/app/django-test/dev/test-1/HELLO_WORLD/lib/python2.6/site-packages',
'/data/app/django-test/dev/test-1/HELLO_WORLD/HELLO_WORLD/..',
'/usr/lib64/python26.zip',
'/usr/lib64/python2.6',
'/usr/lib64/python2.6/plat-linux2',
'/usr/lib64/python2.6/lib-tk',
'/usr/lib64/python2.6/lib-old',
'/usr/lib64/python2.6/lib-dynload',
'/usr/lib64/python2.6/site-packages',
'/usr/lib64/python2.6/site-packages/gst-0.10',
'/usr/lib64/python2.6/site-packages/gtk-2.0',
'/usr/lib/python2.6/site-packages',
'/usr/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg-info',
'/data/app/django-test/dev/test-1/virtual/lib/python3.3/site-packages',
'/data/app/django-test/dev/test-1/HELLO_WORLD/']


Just to make it clear, that python inside the virtual env is python 3.3.2:

(guillem-py3-dj17-test)ndoluxel002:/data/app/guillem-py3-dj17-test/bin# pwd
/data/app/guillem-py3-dj17-test/bin
(guillem-py3-dj17-test)ndoluxel002:/data/app/guillem-py3-dj17-test/bin# which python
/data/app/guillem-py3-dj17-test/bin/python
(guillem-py3-dj17-test)ndoluxel002:/data/app/guillem-py3-dj17-test/bin# ./python --version
Python 3.3.2


____


So, for some reason which most possibly lies with a misconfiguration from my part, Apache ignores the fact that theer is another python installed in the system.


I believe this happens because the installed mod_wsgi is not compatible:

mod_wsgi-3.2-3.el6.x86_64

Is this the case?




For whatI read here:

http://code.google.com/p/modwsgi/wiki/SupportForPython3X

I should be fine with mod_wsgi 3.2

___________________


What I have tried:

- Install apache 2.4 alongside 2.2. Even if I can get a suitable mod_wsgi mod, I get library dependancy problems, one with python 2.7, which should be solvable, and another for glibc, which may be more triky.

All, in it looks like Centos 6.5 + Python 3.3.X + Django 1.6 is not possible for the moment.

Am I right?

If there is a way, please let me know!

Many thanks in advance.

Tom Evans

unread,
May 2, 2014, 10:28:00 AM5/2/14
to django...@googlegroups.com
On Fri, May 2, 2014 at 12:11 PM, Guillem Liarte
<guillem...@googlemail.com> wrote:
> Hello,
>
> I have looked through the web in several different especialised forums but I
> cannot find the way to do this properly.
>
> My aim is to have an environment to host Django applications running Centos
> 6. So far I have managed to:
>
> - Get Centos 6.5 + Ptython 3.3.2 + Django 1.6 (virtual env), running a test
> application using python's webserver. Time to move into Apache.
> - I manage to get it working from Apache but instead of Python 3.3.2, it
> uses the Python 2.6 installed in the system. No matter if I launch apache
> from the virtual environment, even once I have enabled python3.
>

mod_wsgi is linked against a specific version of python, chosen at
compile time. The people who compiled the mod_wsgi package in CentOS
chose to link it against python 2.6, and not python 3.3.

You will need to obtain, or install manually, mod_wsgi compiled
against python 3.

Cheers

Tom

PS: Why Python 3.3 and not Python 3.4?

Brad Pitcher

unread,
May 2, 2014, 10:37:35 AM5/2/14
to django-users
What does your Apache vhost config look like? You will need to add a WSGIDaemonProcess directive where you can specify the python path for the virtual environment, like so:

WSGIDaemonProcess processname user=wsgi group=apache processes=1 threads=10 umask=0022 display-name=displayname python-path=/data/app/guillem-py3-dj17-test/lib64/python3.3/site-packages/

---------
Brad Pitcher


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/aab4ab40-d466-4903-b75d-8a99285cad3f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Guillem Liarte

unread,
May 5, 2014, 5:45:57 PM5/5/14
to django...@googlegroups.com
Hello Brad,

Thanks for the suggestion, I was suspecting something like that. I will let you know how it goes.

Where do you find this? I Could not find anything like that in the wsgi documentation.

Thank you,

Guillem

Brad Pitcher

unread,
May 5, 2014, 5:47:45 PM5/5/14
to django-users
It's just something that was passed down to me from a senior programmer :-)

---------
Brad Pitcher


Guillem Liarte

unread,
May 5, 2014, 5:49:23 PM5/5/14
to django...@googlegroups.com, teva...@googlemail.com
Hello Tom,

Yes, I tried to compile wsgi with python 3.3, but I got error after error. Instead I came back to the original quest of finding a compiled version that works of, as it has also been indicated, to le apache know that that I wish to use a different python.

Any specific tips when compiling wsgi with python 3? I will see to produce the error I was getting once again.

Many thanks for replying.
Guillem

Guillem Liarte

unread,
May 6, 2014, 6:01:00 PM5/6/14
to django...@googlegroups.com
Hello again.

The solution for the incorrect version came as a combination of both Tom's and  Brad's answer.

I could compile a mod_wsgi 3.4 with my python and I used the recommended configuration. Now I get:

[Tue May 06 23:51:30 2014] [notice] Apache/2.2.15 (Unix) DAV/2 mod_wsgi/3.4 Python/3.3.2 configured -- resuming normal operations
Fatal Python error: Py_Initialize: Unable to get the locale encoding
Fatal Python error: Py_Initialize: Unable to get the locale encoding


I am forcing the following locale:

LANG="en_GB.UTF-8"
LC_ALL="en_GB.utf8"
LC_CTYPE="C"
LC_NUMERIC=en_GB.utf8
LC_TIME=en_GB.utf8
LC_COLLATE="en_GB.utf8"
LC_MONETARY=en_GB.utf8
LC_MESSAGES="en_GB.utf8"
LC_PAPER=en_GB.utf8
LC_NAME=en_GB.utf8
LC_ADDRESS=en_GB.utf8
LC_TELEPHONE=en_GB.utf8
LC_MEASUREMENT=en_GB.utf8
LC_IDENTIFICATION=en_GB.utf8

So I do not understand why it is not working. I have also /etc/sysconfig/httpd:

export LANG=en_GB.UTF-8
export LC_ALL=en_GB.UTF-8
export LC_CTYPE=C
export LC_NUMERIC=en_GB.UTF-8
export LC_TIME=en_GB.UTF-8
export LC_COLLATE=en_GB.UTF-8
export LC_MONETARY=en_GB.UTF-8
export LC_MESSAGES=en_GB.UTF-8
export LC_PAPER=en_GB.UTF-8
export LC_NAME=en_GB.UTF-8
export LC_ADDRESS=en_GB.UTF-8
export LC_TELEPHONE=en_GB.UTF-8
export LC_MEASUREMENT=en_GB.UTF-8
export LC_IDENTIFICATION=en_GB.UTF-8


But I still get the locale encoding problem.  Do you guys have any suggestions?

Thanks!

Timothy W. Cook

unread,
May 6, 2014, 6:20:00 PM5/6/14
to django...@googlegroups.com

On Tue, May 6, 2014 at 7:01 PM, Guillem Liarte <guillem...@googlemail.com> wrote:


But I still get the locale encoding problem.  Do you guys have any suggestions?

I do not recall the exact error I had with this config (once you corrected those you mentioned) but eventually I had to set:

$setenforce 0

to disable SELinux security.  I am sure that there is a way around this but I haven't had a need to fix it yet. 

HTH,
Tim
 


============================================
Timothy Cook
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook

Guillem Liarte

unread,
May 7, 2014, 10:33:23 AM5/7/14
to django...@googlegroups.com
Timothy,

Thanks you, but SELinux here does not seem to be the issue. I tried with enforcing/permissive/disabled and the effect is the same.

I belive the problem to be in the os path in the seetings:

---

import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
...
...





--

in wsgi.py :

----
import os, sys
sys.path.append('/data/app/guillem-py3-dj17-test/guillem_test/guillem_test')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "guillem_test.settings")

---

python -c "import sys; print(sys.path)"
['', '/data/app/guillem-py3-dj17-test/lib64/python33.zip', '/data/app/guillem-py3-dj17-test/lib64/python3.3', '/data/app/guillem-py3-dj17-test/lib64/python3.3/plat-linux', '/data/app/guillem
-py3-dj17-test/lib64/python3.3/lib-dynload', '/opt/rh/python33/root/usr/lib64/python3.3', '/opt/rh/python33/root/usr/lib/python3.3', '/data/app/guillem-py3-dj17-test/lib/python3.3/site-packa
ges']




I am reading about the differnces for mod_wsgi from python2.x to python3.x but I fail to find clear documentation about how the wsgi.py and  settings.py should look like in python3.

Guillem Liarte

unread,
May 13, 2014, 5:14:57 AM5/13/14
to django...@googlegroups.com
Has anybody being able to solve this problem with the locale in virtual env?

I am stuck with it for the moment.

It is just that Centos 6 + Django 1.7 (python3.x ) is a no-go?

Thanks.

Timothy W. Cook

unread,
May 13, 2014, 7:04:00 AM5/13/14
to django...@googlegroups.com
I am not sure where your problem is with locale.  Did you ever accomplish recompiling mod_wsgi for Python 3.3? 

This site http://www.ccdgen.com is Django 1.6, Python 3.3 and Apache 2.2 on CentOS 6.5 

I recompiled mod_wsgi as per instructions I found somewhere on the WWW.  Sorry I do not have the link now.  As I recall, there were several additional packages I had to track down and install. 

The Django code is in a User home subdirectory and the 'apache' user in the 'ccdgen' group. 

The relevant sections of httpd.conf are:
Alias /icons/ "/var/www/icons/"

<Directory "/var/www/icons">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

Alias /static/ "/var/www/ccdgen/static/"

<Directory "/var/www/ccdgen/static">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>



and 

WSGIScriptAlias / /home/ccdgen/CCDGEN2/ccdgen/mlhim/wsgi.py
WSGIPythonPath /home/ccdgen/CCDGEN2/ccdgen/ccdgen:/home/ccdgen/CCDGEN2/ccdgen:/home/ccdgen/CCDGEN2/lib/python3.3/site-packages
<Directory /home/ccdgen/CCDGEN2/ccdgen>
   <Files wsgi.py>
     Order allow,deny
     Allow from all
   </Files>
</Directory>


Maybe something here will 'stick out' as a solution for you.

HTH,
Tim




 


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.

For more options, visit https://groups.google.com/d/optout.



--

Guillem Liarte

unread,
May 13, 2014, 6:46:25 PM5/13/14
to django...@googlegroups.com
Tim,

Yes!

I see now what I was doing wrong; I was setting the path in the Django settings.py (as I had found in the documentation), however, OF COURSE, that is irrelevant because it could ever get there before mod_wsgi being aware of where to look for libraries. Damn!

I was having the right idea, but digging in the wrong direction. Thanks again, this puts me back on track :-)

Thanks everybody in this thread, I have learn a lot in the way.

Regards,

Guillem

John Schmitt

unread,
Aug 18, 2014, 5:39:15 PM8/18/14
to django...@googlegroups.com
I realise I'm late to this conversation, but I had to do this for my own use recently except that I used Centos 7 and Python 3.4.

To do this for me I hacked up a bash script and put it on github:

https://github.com/marmalodak/centos_python3_django_setup/blob/master/mkenv3

I compile both Python 3.4 and mod_wsgi 3.4.

Before posting this message, I replaced the name of the project for which I used this script to make it generic. Please consider it a starting point.
Reply all
Reply to author
Forward
0 new messages