Okay, so I'm sitting here bashing my head against the desk. I've been googling this for what seems the past hour. I cannot find any relative good links for making Python work with WAMP server. Yes, I understand how CGI scripts work. Unfortunately, I have no idea how to configure Apache to run with Python or anything. I have this script:

#!C:/python26/python.exe -u
print "Content-type: text/html\n"

print('''\
<html>
<head>
<title>Hello</title>
</head>
<body>
Hello world!
</body>
</html>
''')

That I want to run using WAMP. Thought it'd be simple, no? xD Anyways, can anyone give me a detailed explanation on how to get it to work? Without Mod-Python would be nice, because I have no idea what that is, and I keep hearing different thigns about it, such as you don't need it, blah blah blah. Please and thank you.

Dani AI

Generated

Short practical guide (since fixed it but didn’t post details) that fills the gaps left by the thread and the PHP-vs-Python side-discussion from and .

For quick single scripts: use CGI. Enable Apache’s CGI handler, allow ExecCGI for the directory you want, and tell Apache to treat “.py” as a CGI script. Example httpd.conf tweaks (Windows/WAMP paths shown as examples — adapt to your install):

LoadModule cgi_module modules/mod_cgi.so

<Directory "c:/wamp/www/">
  Options +ExecCGI
  AddHandler cgi-script .py
</Directory>

Put scripts in the configured cgi-bin (or a directory with ExecCGI). Make sure the top of the script points to your python executable (Windows absolute path or #!python) and that the script emits the HTTP header (Content-type) first. See Apache’s CGI how-to for details. (Apache CGI HowTo). (httpd.apache.org)

For real web apps (Django/Flask) use WSGI — mod_wsgi is the usual, supported option (mod_python is old/deprecated). Typical lightweight config:

LoadModule wsgi_module modules/mod_wsgi.so
WSGIScriptAlias /myapp "c:/path/to/myapp.wsgi"

<Directory "c:/path/to">
  Require all granted
</Directory>

Install a mod_wsgi binary that matches your Apache+Python versions or use pip install mod_wsgi + mod_wsgi-express for development. Note Windows has caveats (daemon mode limitations and binary compatibility). (mod_wsgi — Getting Started). (modwsgi.readthedocs.io)

Quick troubleshooting and tips: enable cgitb while developing to see tracebacks in the browser (import cgitb; cgitb.enable()), check WAMP’s Apache error log (e.g. c:\wamp\logs\apache_error.log) and run httpd -t to test your config. For fast local development consider python -m http.server or framework dev servers instead of touching Apache. (Python cgitb docs, python -m http.server). (docs.python.org)

This covers the minimal, repeatable steps that make Python run under WAMP and points to the canonical docs for deeper details.

Recommended Answers

All 5 Replies

Never mind, I got it all working out

Pray do enlighten us.

Python is extremely uncommon for use with websites. Sure, it's powerful, easy, but when it comes to real website (assuming that's what you want to do), you need php.

Python is extremely uncommon for use with websites. Sure, it's powerful, easy, but when it comes to real website (assuming that's what you want to do), you need php.

Very untrue.
"Real website"?
Is washingtonpost real enough?

PHP is great, but Rails and Django are simply much more powerful.
ASP.NET is also often considered better than PHP.

You definitely don't "need" php.

I have tried all and found strengths in all. So, I presume that it is based on personal preferences and personality. I found python good as a programming language. I wanted to check if it is as good as a web development environment?

is one such article to learn how to configure Django/Python for ?AMP.

Another is http://jyotirmaya.blogspot.com/2008/11/xampp-python-django.html ensure to follow the comments where from I got my solution.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.