django on rhel5 with both python2.4 and python2.7 confusion

60 views
Skip to first unread message

David Malcolm

unread,
May 7, 2014, 5:08:40 AM5/7/14
to django...@googlegroups.com
I have been tasked with finishing a build for production that was interrupted due to another staff member leaving at short notice. It's RedHat Enterprise Linux 5 and there are two versions of python on the box. If I type python I get version 2.7. However if I try and use django-admin.py I find that it is trying to use python version 2.4. How do I specify to Django that I want to use python 2.7? I've seen multiple supposed answers on the net but nothing actually seems to answer my specific question. I'm fairly experienced on linux but have never had to setup django and python before. My Apache, php, phpMyAdmin setup is all working properly (after I sorted out some other issues),  but my second question is how do I wire up python/django to apache (or httpd as rhel5 calls it). I've tried using mod_wsgi but have been told I must use mod_python. Advice or pointers to relevant urls are much appreciated.
Thanks Dave, Melbourne

Timothy W. Cook

unread,
May 7, 2014, 7:37:10 AM5/7/14
to django...@googlegroups.com
A good place to start is with this thread:

Be sure to include CentOS in your searches for clues about this setup since many people use CentOS instead of RHEL. 

HTH,
Tim



On Wed, May 7, 2014 at 6:08 AM, David Malcolm <djma...@gmail.com> wrote:
I have been tasked with finishing a build for production that was interrupted due to another staff member leaving at short notice. It's RedHat Enterprise Linux 5 and there are two versions of python on the box. If I type python I get version 2.7. However if I try and use django-admin.py I find that it is trying to use python version 2.4. How do I specify to Django that I want to use python 2.7? I've seen multiple supposed answers on the net but nothing actually seems to answer my specific question. I'm fairly experienced on linux but have never had to setup django and python before. My Apache, php, phpMyAdmin setup is all working properly (after I sorted out some other issues),  but my second question is how do I wire up python/django to apache (or httpd as rhel5 calls it). I've tried using mod_wsgi but have been told I must use mod_python. Advice or pointers to relevant urls are much appreciated.
Thanks Dave, Melbourne

--
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/74af440c-b42d-4fcd-abfa-74da94958b73%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

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

Kelvin Wong

unread,
May 8, 2014, 1:09:34 AM5/8/14
to django...@googlegroups.com
Question one...

The gist is:

1. Set up Virtualenv and Virtualenvwrapper (lots of howtos on the web for this - find one written in the last year)
2. Set correct environment keys to point to the right Python (similar to the following, you paths may be different)

# ~/.bashrc
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python2.7
export VIRTUALENVWRAPPER_VIRTUALENV=$HOME/.local/bin/virtualenv-2.7
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Projects
source $HOME/.local/bin/virtualenvwrapper.sh

3. Make a virtualenv: like this $ mkvirtualenv myappenv
4. Install Django into the virtualenv (you should have been dumped into it after you made it): (myappenv) $ pip install Django
5. Check which django-admin.py you are using

$ which django-admin.py
/home/myuser/.virtualenvs/myappenv/bin/django-admin.py

Hint: Webfaction uses CentOS with many different types of Pythons. Searching their support website may be helpful.

---

Question two: Use mod_wsgi rather than mod_python. See warning at the top of the Dj1.4 docs

https://docs.djangoproject.com/en/1.4/howto/deployment/modpython/

Setting up a Django app is more complex than setting up a PHP app (one persons opinion). The benefit is that at the end of the ordeal you will be running Python and not PHP (one persons opinion).

:)

K

David Malcolm

unread,
May 12, 2014, 6:50:42 AM5/12/14
to django...@googlegroups.com
Hi Timothy

thanks for your suggestions. I'm still on the path. I'll put more details in my reply to WongoBongo below.

cheers
Dave

David Malcolm

unread,
May 12, 2014, 7:09:38 AM5/12/14
to django...@googlegroups.com
thanks for your reply WB.

I was hoping to avoid virtualenv. My webapp is a frontend to a vulnerability scanner in a large corporation.
They are very picky about what I can use and what I can't. Is virtualenv suitable for such a production system?
They insist that I cannot use mod_wsgi (it annoys me intensely, but hey that's life) and HAVE to use mod_python.
Is there any other way to get this working without virtualenv?

I also have no choice about OS. rhel6 is undergoing an approval process as an SOE but it won't happen any time soon :(

I am so close to getting this working now but it does indeed look like django (httpd) is using python2.4.
Note that "which python" gives me 2.7 - what is causing django to use python & mod_python 2.4? mod_python is installed for 2.7.

Mod_python error: "PythonHandler django.core.handlers.modpython"
Traceback (most recent call last):
File "/usr/lib64/python2.4/site-packages/mod_python/apache.py", line 287, in HandlerDispatch
log=debug)
File "/usr/lib64/python2.4/site-packages/mod_python/apache.py", line 461, in import_module
f, p, d = imp.find_module(parts[i], path)
ImportError: No module named django

thanks for your help.
cheers Dave

Timothy W. Cook

unread,
May 12, 2014, 7:34:48 AM5/12/14
to django...@googlegroups.com
I can't imagine virtualenv being a vulnerability risk.  AFAIK; All it does is create a set of scripts to isolate the executing Python environment. 

In fact, I would almost say that it improves your ability to know EXACTLY what is in your environment irregardless of the rest of the machine.  

Frankly, I do not create any Python code outside of a specified virtualenv.  Web apps or any other scripts or apps. 

 


--
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.

Tom Evans

unread,
May 12, 2014, 9:11:01 AM5/12/14
to django...@googlegroups.com
On Mon, May 12, 2014 at 12:09 PM, David Malcolm <djma...@gmail.com> wrote:
> thanks for your reply WB.
>
> I was hoping to avoid virtualenv. My webapp is a frontend to a vulnerability scanner in a large corporation.
> They are very picky about what I can use and what I can't. Is virtualenv suitable for such a production system?

If I ever come across a production system where a python app is not
installed in a virtualenv, I consider that a bug. virtualenv is the
basis of all of our python production systems (our dev systems too).

> They insist that I cannot use mod_wsgi (it annoys me intensely, but hey that's life) and HAVE to use mod_python.

mod_python is old, insecure, unmaintained, unmanaged - and most
importantly - not supported for django.

> Is there any other way to get this working without virtualenv?

Find the right person to talk to your in your org, tell them that
mod_python is dangerous, and that virtualenv is the industry standard
way of deploying a python application, and that wsgi is the industry
standard way of connecting a python web application to a web server.

Cheers

Tom

Kelvin Wong

unread,
May 17, 2014, 2:21:54 AM5/17/14
to django...@googlegroups.com
I haven't used mod_python in such a long time that I don't recall the configuration details. Off the top of my head, you might want to check how to add the Python 2.7 site-packages folder to the path that mod_python searches for python modules like Django.

Reply all
Reply to author
Forward
0 new messages