Installez mod_python pour Apache 2.2.21, Python 2.5.4 sur Mac OS X 10.6

J’ai pu installer apache et python avec succès depuis la source.

J’ai installé mod_python avec la commande configure suivante:

./configure --prefix=/usr/local/python/lib/python2.5/site-packages/mod_python --with-apxs=/usr/local/apache/bin/apxs --with-python=/usr/local/python/bin/python2.5 

J’ai copié mon fichier de test (mptest.py) dans le dossier htdocs / test, voici mon mptest:

 from mod_python import apache def handler(req): req.log_error('handler') req.content_type = 'text/plain' req.send_http_header() req.write('mptest.py\n') return apache.OK 

J’ai aussi copié mon fichier .htaccess vers le dossier htdocs / test, voici mon fichier .htaccess:

 AddHandler mod_python .py PythonHandler mptest PythonDebug On 

Je reçois l’erreur, erreur de serveur Internet et voici mon journal d’erreur apache:

 [Wed Nov 16 17:10:48 2011] [notice] mod_python: Creating 8 session mutexes based on 256 >max processes and 0 max threads. [Wed Nov 16 17:10:48 2011] [notice] mod_python: using mutex_directory /tmp [Wed Nov 16 17:10:48 2011] [notice] Apache/2.2.21 (Unix) PHP/5.2.17 mod_python/3.3.2-dev-20080819 Python/2.5.4 configured -- resuming normal operations [Wed Nov 16 17:11:00 2011] [error] make_obcallback: could not import mod_python.apache.\n ImportError: No module named mod_python.apache [Wed Nov 16 17:11:00 2011] [error] make_obcallback: Python path being used "['/Library/Python/2.5/site-packages/setuptools-0.6c11-py2.5.egg', '/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python25.zip', '/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5', '/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-dynload', '/Library/Python/2.5/site-packages', '/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/PyObjC', '/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/wx-2.8-mac-unicode']". [Wed Nov 16 17:11:00 2011] [error] get_interpreter: no interpreter callback found. [Wed Nov 16 17:11:00 2011] [error] [client ::1] python_handler: Can't get/create interpreter., referer: http://localhost/test/ 

mon mod_python.so est lié au python du système que je ne veux pas, la preuve est ci-dessous. Comment puis-je le lier à Python installé par moi?

 Mac-Pro:~ user$ otool -L /usr/local/apache/modules/mod_python.so /usr/local/apache/modules/mod_python.so: /System/Library/Frameworks/Python.framework/Versions/2.5/Python (compatibility version 2.5.0, current version 2.5.4) 

/usr/lib/libSystem.B.dylib (version de compatibilité 1.0.0, version actuelle 125.0.0) /usr/lib/libgcc_s.1.dylib (compatibilité version 1.0.0, version actuelle 625.0.0)

Je veux juste afficher mptest.py dans mon navigateur Web, quelqu’un peut-il m’aider?

Je sais que mod_wsgi est une meilleure option que mod_python, mais je dois faire fonctionner mod_python. Je vais essayer mod_wsgi plus tard.

Merci.

J’ai peur de ne pas pouvoir aider avec mod_python. Nous avons changé tout notre code de mod_python en faveur de mod_wsgi et nous n’avons jamais regardé en arrière.

mod_wsgi a quelques fonctionnalités intéressantes – sans oublier la possibilité de créer facilement du code de débogage / diagnostic qui peut être entièrement exécuté à partir de python sans avoir à exécuter Apache (ce qui ouvre la possibilité d’exécuter des débogueurs et d’imprimer directement sur stdout).

Si vous suivez le chemin de wsgi, envisagez d’utiliser Webob pour gérer les objects Request / Response.

Voici comment vous codez votre exemple dans mod_wsgi

 # --------- EXAMPLE ---------- from webob import Response def application(environ, start_response): res = Response() res.content_type = 'text/plain' res.body = "mptest.py\r\n" return res(environ, start_response) 

Bonne chance.