Run python in xampp for windows

  • Filter
  • Time
  • Show
Clear All
new posts

  • Run python in xampp for windows

    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 in the end
    It will look something like this
    <IfModule dir_module>
        DirectoryIndex index.php index.cgi index.asp index.shtml index.html index.htm \
                       default.php default.cgi default.asp default.shtml default.html default.htm \
                       home.php home.cgi home.asp home.shtml home.html home.htm
    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

    PHP Code:
    print "Content-Type: text/html\n"
    print "This is cool" 
    save the file as in htdocs & open http://localhost/
    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

    PHP Code:
    print "Content-Type: text/html\n"
    import urllib2

    Last edited by softwarefreak; 18.09.12, 02:52.