3

I'm looking for the fast, easy (all default settings) way of installing Python on my windows machine so that Apache can use it. I currently have a Windows 7 installation with Apache and PHP working. I want to try and make some simple web pages in Python, just to play around with Python for a bit and learn a thing or two. I downloaded and installed Python 3.2 Python 2.7.2 (As advised below). What do I do next? I would like to make a "Hello World". Do I need mod_python or can I do without? I assume I need to tell Apache somehow that Python is available. I probably need to make an "index.py" file, or something similar?

I'm not directly looking for tutorials on the Python language itself, but just for some steps to make the simplest of the simplest script (Hello World) work on my current system.

Basically I'm looking for the Python equivalent of the following php script to work in my Apache:

<html>
 <head>
  <title>Hello World</title>
 </head>
 <body>
  <?= "Hello World"; ?>
 </body>
</html>

2 Answers 2

4

First of all, especially in the web sector it's better to stay with python 2 (2.7) for now. Lots of frameworks and libraries are not py3-ready yet.

Then you might want to use mod_wsgi instead of mod_python which is deprecated and not available in binary form for recent python versions (and using old python versions such as 2.5 is bad).

Finally, unlike PHP it's usually not a good idea to write python webapplications with the idea of 1:1 mappings between files and urls. To get started with something nice, have a look at the Flask microframework. It has some good examples and a full tutorial. And to make it even better, you don't need Apache for it during development as you can simply run a python-based developmont server.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for your answer. I'm a little in the dark as to why a framework is such a good idea. Can I not just make a 1 file site that represents the python equivalent of the php example in my question?
WSGI is a very very low level interface. PHP in comparison provides a lot of higher level functionality which simply will not exist. If you use WSGI API directly, you will have to reinvent the wheel and for things which may affect the security of your site, likely get it plain wrong. A micro framework like Flask, where things can still be in one file if need be, will do all the mundane stuff for you like handling query strings or form posts, as well as pulling apart headers etc etc. So, it will save you a lot of work.
And in the end your code will look nicer since you won't have the disgusting mix of code and markup in the same file like most PHP beginners do (at least when using flask you'll use Jinja2 instead).
I accepted Xearxess' answer because it answers my (now rather silly) question better. I gave you +1 for your information on frameworks which I think is indeed very relevant now that I'm reading it. I hope this seems just to you both.
3

You can use mod_python (deprecated and not recommended) or better mod_wsgi.

Look at:

2 Comments

Thanks for your answer, I have installed Python 2.7.2 instead of 3 and installed mod_wsgi as you advised. I'm little lost now as what to do next. Apache is running with the mod installed. What steps to take to make my first index document that prints "hello world"?
Bazzz. The quick configuration guide that you were pointed to shows you how to do the hello world program. Did you read it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.