Run python in xampp for windows

Started on the old forum in September 2012 · view the original in the archive · old links redirect here

No replies · 6,452 views · started 14 years ago · 2 min read

softwarefreak Senior · 349 posts #1

The setup takes nearly 2 min.

Assuming that you have already installed xammp in your windows PC, You can follow the below steps to run python in your localhost

STEP 1:

Download & install the latest version of python from here Download Python click on the windows installer of any version

STEP 2:

Install in any directory of your harddrive

STEP 3:

Open the directory where xammp was installed Go to apache >> conf

You'll see a file named httpd.conf Open it in any text editor & put the below codes in the end of that file

AddHandler cgi-script .py
ScriptInterpreterSource Registry-Strict

The next step is optional

STEP 4: In same file search for <IfModule dir_module> When you've found it put index.py in the end It will look something like this

<IfModule dir_module>
    DirectoryIndex index.php index.pl index.cgi index.asp index.shtml index.html index.htm \
                   default.php default.pl default.cgi default.asp default.shtml default.html default.htm \
                   home.php home.pl home.cgi home.asp home.shtml home.html home.htm index.py
</IfModule>

STEP 5: That's all for editing, now restart apache from your xampp control panel

STEP 6:

Open a text editor & test python now

But wait at the beginning of your script you need to specify the path where you've installed python

In my case its C:/python27/python.exe In your case it may be different, depending up on the version you've installed python & the directory of your hard drive

#!C:/Python27/python.exe
print "Content-Type: text/html\n"
print "This is cool"

save the file as test.py in htdocs & open http://localhost/test.py If everything goes well, You'll see the text This is cool

Now, who the hell is gonna install python just to see the stupid text "This is cool" ?!

Here's the code to grab a web page w/ python

#!C:/Python27/python.exe
print "Content-Type: text/html\n"
import urllib2
response = urllib2.urlopen('http://python.org/')
html = response.read()
print html

LOL


I need some facebook likes, can you please help me 🤝 http://facebook.com/softwarefreakin I noticed social media is really powerful 🧙 Well DONE is better than well SAID

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close