Apache mod_wsgi 32-bit/64-bit Python compatibility - python

I use Zend Studio / Zend Server for developing my PHP-based web sites, but now I'm taking a course in Python, and I want to learn Django.
I have a Windows 7 AMD-64 machine, and am using 64-bit Python 2.6 (version 2.6 is required by the course), and that part works fine.
My problem is trying to add mod_wsgi to my Zend Server's 32-bit Apache installation. I've downloaded several versions of mod_wsgi 32-bit Windows binaries for Python 2.6, and copied them to C:Program Files (x86)\Zend\Apache2\modules directory, edited httpd.conf and added:
LoadModule wsgi_module modules/mod_wsgi.so
restarted Apached2.2-Zend, and then tested if mod_wsgi was loaded at the command prompt with:
httpd -t -M
However, mod_wsgi does not show up on the list of loaded modules.
I finally figured this might not be working because I cannot mix-and-match 64-bit Python 2.6 with 32-bit ZendServer Apache2.2.
So here's the meat of my question:
Can I install a 64-bit version of Apache 2.2 and run that at the same time as ZendServer Apache2.2 (but configure the 64-bit version so it doesn't listen on the same ports as my ZendSever Apache2.2) so all my local PHP virtual hosts still work? Maybe I would have better luck getting mod_wsgi to load with this Apache?
Or, would it be better to install a 32-bit version of Python (probably a higher version like Python 2.8, since I only need Python 2.6 for my coursework, and I am trying to get Django working just for my own web site development)? Would that allow my ZendServer Apache2.2 to load mod_wsgi? Also, how does Apache figure out which installation of Python it should be using if I have both on my Windows 7 machine?

Can I install a 64-bit version of Apache 2.2 and run that at the same time as ZendServer Apache2.2 (but configure the 64-bit version so it doesn't listen on the same ports as my ZendSever Apache2.2)
Yes, you can.
You've already thought about the hardest problem: that it can't listen on the same ports.
A related problem is that some people's networks don't allow them to make outgoing connections to, say, port 8080; if you want to deal with that, you'll need to set up your ZendServer to act as a forward proxy for the other server. But that's really about it.
The only other problem is that you need to make sure your two copies of Apache don't try to share the same config files, etc. (and you may not want both of them on your PATH, either).
Or, would it be better to install a 32-bit version of Python (probably a higher version like Python 2.8
There is no 2.8, and never will be. The last 2.x version is 2.7 (although it continues to get bug fixes, and is up to 2.7.5). If you want something higher, you have to go to 3.x. If everything you need runs on 3.3 (and Django 1.5+ does), and you're willing to learn the small changes, you should consider this. But if you want to stick with what you already know, get 2.7.5.
Would that allow my ZendServer Apache2.2 to load mod_wsgi?
Well, not if you're using a mod_wsgi for Python 2.6 and install a Python 2.7 or 3.3… or using a mod_wsgi for native Python and install a Cygwin Python… etc. But I suspect you already know that (given "I've downloaded several versions of mod_wsgi 32-bit Windows binaries for Python 2.6").
Other than that, yes. As long as everything is built and configured right, it will work. (I have no idea what particular packages you downloaded and installed, so I can't promise whether they will work, of course.)
Also, how does Apache figure out which installation of Python it should be using if I have both on my Windows 7 machine?
This is configurable. I believe the default is to use either whatever it finds first on your PATH, or whatever shows up as the "default python 2.x" in your registry settings, as used by the Python command-line launcher described in PEP 397. (And of course if that Python is not the one it was built against, it will fail to start up.)

Related

How to upgrade default python version on linux (redhat)?

Could you please let me know the best way to upgrade python on linux? I need it because my redhat linux machine is offering 2.6.6 version as default. If I install python 2.7 then it breaks yum and mod_wsgi. Has anyone found out the best way to do it? I really need this for flask web development.
I had tried https://danieleriksson.net/2017/02/08/how-to-install-latest-python-on-centos/ steps but it caused issues with mod_wsgi (which was on 2.6).
Just to add - I have read and tried almost everything related to this topic but couldn't succeed. Hence I am asking this question if someone has already figured out a way for this.
In addition to what SpliFF said, you can create a virtual environment and set which python version you would like to use by using the -p flag.
You can install multiple versions of python side-by-side. What makes one "default" is the python and python2 symlinks in /usr/bin.
However you should definitely not change the default python on Redhat for the reasons you list and more.
Instead, you will need to tell WSGI which python to use. This question covers that: Run mod_wsgi with virtualenv or Python with version different that system default
Also, according to this answer ( Deploying Python Flask App on Apache with Python version installed in Virtual Environment Only ) you may need to compile a custom wsgi against the python version you want to use.
For RedHat based operating systems, use SCL versions of Python.
https://www.softwarecollections.org/en/
They are installed in separate area so they do not conflict.
There is no mod_wsgi in SCL, so use pip method to install it and then link Apache to it. Details in:
https://pypi.python.org/pypi/mod_wsgi

Apache looks for Python 2.6 instead of 2.7

My OS already has Python 2.6.6 and I've installed Python 2.7.3 as an alternative. (Python's working fine). I've installed mod_python also, but when I try to execute a Python file on an Apache server, it shows me a list of errors where I can see it seeks to Python 2.6.6 library. But I need to work with python 2.7.3. Can anyone help me to get rid of it?
Actually I don't know if Apache is configured well or not!
I'm on CentOS 6.2.
Have a look at this. However, note this part:
If you want to use a different version of major/minor version of Python than currently used, you must recompile mod_wsgi against the alternate version of Python.
I'm not quite sure that if you simply swap the WSGIPythonHome variable it will work. If you have installed mod_wsgi with yum, you will probably have a mod_wsgi for Python 2.6.x, which is distributed with CentOS 6.x. If you really want to use Python 2.7.x, you may have to build mod_wsgi from source (which is actually not that hard).

Need MAMP to use (an older version of) Python

One of my sites requires python and cherrypy. Locally, I need to get all of this running with MAMP. I have the site running in MAMP with the exception of features reliant on Python. I need to run python 2.5. My OS version is 2.7.
How do I set this up? I seem to have 2.5 installed in addition to 2.7 and 2.6
which python
/usr/bin/python
which python2.5
/usr/bin/python2.5
but the usr/bin/python2.5 is an alias to: System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5
How do I make python2.5 available to MAMP without screwing up the vers OSX needs?
It's a drupal site, MAMP is handling everything php related, and perhaps I wrongfully assumed it needed to have anything to do with the python scripts of the site. As I read more about cherrypy, it seems cherrypy serves the python scripts, and I do have cherrypy running (localhost:8080 test works anyway), so perhaps all I need to do is make sure python2.5 is being used instead of the default? (2.7)
You've got the right idea. You definitely want to leave the OS python version alone. Or you could be breaking multiple dependencies. We launch our cherrypy instances in our rc.local script at boot. This is where you specify which version of python to use when executing your cherrypy app.
Our rc.local script looks like this:
/opt/Python-3.2/python /var/www/html/appname/webapp.py > stdout.log &

Is it possible, and/or advisable to develop Django web applications on OS X (10.6.4 and 10.5.8) using Python 2.6.5 64-bit? Why?

I'm trying to decide on which architecture to choose for developing Django 1.0.x through Django 1.2.1. I've managed to get MySQL, MySQLdb, PIL, and Python 2.65 installed on Snow Leopard using x86 64-bit builds, but I'm curious as to whether or not there is a definitive answer to this question at the moment, and if so, why?
Thank you!
Michaux
Of course it's possible. Advisable? You didn't mention httpd and mod_wsgi, or some other WSGI container. Get one installed and it should be fine.
It certainly is possible: I do it every day.
Some tips:
use virtualenv to sandbox your python packages between projects.
use mod_passenger (via Passenger.prefpane) to make VirtualHosts easier to deal with.
You may need to fiddle a bit harder with things if you run stuff under mod_python, as I recall having to work hard to get a version compiled that worked with the version of apache that is installed by default, and the python I was using.

how do you specify which python executable to use in Django 1.1.1?

I have a RH system running RHEL 5.3, which comes with python2.4 that can't be removed for numerous reasons.
I have been able to build 64-bit RPMS for python 2.6 as an altinstall. It's called with "python26".
How can I tell Django to use this command to get to the proper python version, instead of the default "python".
I can, of course, change the symlink in /usr/bin manually, but i'm looking to fully automate the buildout of these systems, and I'm almost certain this is possible.
Thanks.
Look at virtualenv, you can setup your own environment for django (well, anything) with different lib versions, symlinks etc.
That depends on the deploying method you use. E.g., if you use the django-recommended mod_wsgi deployment, then you must compile it with the correct python version.

Categories

Resources