Using Python with XAMPP

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Using Python with XAMPP

Postby riclags » 26. February 2013 11:50

I've gone through this (http://community.apachefriends.org/f/viewtopic.php?f=16&t=34468) tutorial/how-to but I was wondering if there are any current ways to use Python with XAMPP as the mentioned post is 3 years old.

Also, if that's still the way to get Python working with XAMPP, I have 2 questions:
(1) Which directory are the .reg files placed? Is it under XAMPP or the Python directory?
(2) The shebang portion of the Python code also uses #!/usr/bin/python; is this correct?

Thanks.
riclags
 
Posts: 2
Joined: 26. February 2013 11:42
Operating System: Windows 7

Re: Using Python with XAMPP

Postby Nobbie » 26. February 2013 12:11

riclags wrote:I've gone through this (http://community.apachefriends.org/f/viewtopic.php?f=16&t=34468) tutorial/how-to but I was wondering if there are any current ways to use Python with XAMPP as the mentioned post is 3 years old.


It may be still working, but I would not do so anyway. I dont like the "Registry Hack" and recommend to go the "standard CGI" installation.

riclags wrote:(1) Which directory are the .reg files placed? Is it under XAMPP or the Python directory?


Anyhwere is ok, because this file is NOT used at runtime, you have to "double click" after creation what imports the contents into to your Windows Registry. Anyway, i do not recommend this Registry Hack.

riclags wrote:(2) The shebang portion of the Python code also uses #!/usr/bin/python; is this correct?


Of course NOT, that is the UNIX Pathname of Python. You have to replace that by the real pathname of your Python installation (i.e. #!c:/python/bin/python.exe or similar). If that pathname contains spaces (not recommended) you have to put double quotes around the pathname (#!"c:/program files/python/bin/python.exe"), but it looks ugly anyway.

There is no need for the Registry Hack if you use the Shebang Line instead. If you give *.cgi as extension to your python scripts, it should run "out of the box". If you would like to use a different extension (for example *.py) you only have to edit one line in httdp,conf. Look for "AddHandler cgi-script .cgi ...." (there may be already more than one extension) and simply add .py to this AddHandler (leave one space between the extensions).

Then restart Apache, use the right Shebang Line and thats it - forget everyhing about Registry. If you want CGI scripts being executed in your DocumentRoot (or subsequent folders), apply Option "ExecCGI" in the <Directory ...> Configuration (what is already the case for Xampp installations).
Nobbie
 
Posts: 13170
Joined: 09. March 2008 13:04

Re: Using Python with XAMPP

Postby JonB » 26. February 2013 23:55

Nobbie is 100% correct

Good luck
User avatar
JonB
AF Moderator
 
Posts: 3210
Joined: 12. April 2010 16:41
Location: Land of the Blazing Sun
Operating System: Windows XP/7 - Fedora 15 1.7.7

Re: Using Python with XAMPP

Postby riclags » 27. February 2013 03:39

Nobbie wrote:It may be still working, but I would not do so anyway. I dont like the "Registry Hack" and recommend to go the "standard CGI" installation.


Thanks for clearing things up. I do want to know how to do the "standard CGI" installation.
riclags
 
Posts: 2
Joined: 26. February 2013 11:42
Operating System: Windows 7

Re: Using Python with XAMPP

Postby Nobbie » 27. February 2013 14:08

riclags wrote:I do want to know how to do the "standard CGI" installation.


In that case, you should not ask and waste our time:

riclags wrote:but I was wondering if there are any current ways to use Python with XAMPP


Wasn't that your question? Call it whatever you want (i call it "standard"); but this is the current and best way how to use Python with Xampp.
Nobbie
 
Posts: 13170
Joined: 09. March 2008 13:04

Re: Using Python with XAMPP

Postby hackattack142 » 27. February 2013 15:06

Hello,

Per the Python documentation, which you should take a look at to see the various options, (http://docs.python.org/2/howto/webservers.html) CGI is no longer recommended.

It recommends you use WSGI (see mod_wsgi at https://code.google.com/p/modwsgi/).

I have used mod_wsgi to host a Django app and it worked alright.
XAMPP Control Panel Developer
Latest CP: viewtopic.php?f=16&t=48932
hackattack142
 
Posts: 701
Joined: 20. May 2011 23:29
Operating System: Windows 7 Ultimate SP1 64-Bit

Re: Using Python with XAMPP

Postby JonB » 27. February 2013 17:17

I was not aware mod_wsgi was included with XAMPP
User avatar
JonB
AF Moderator
 
Posts: 3210
Joined: 12. April 2010 16:41
Location: Land of the Blazing Sun
Operating System: Windows XP/7 - Fedora 15 1.7.7

Re: Using Python with XAMPP

Postby hackattack142 » 27. February 2013 23:59

To be clear, it is not included. You would have to either compile it yourself or find a compatible precompiled version.

If you prefer to not get any additional modules/components, you are pretty much stuck with the CGI method.
XAMPP Control Panel Developer
Latest CP: viewtopic.php?f=16&t=48932
hackattack142
 
Posts: 701
Joined: 20. May 2011 23:29
Operating System: Windows 7 Ultimate SP1 64-Bit

Re: Using Python with XAMPP

Postby JonB » 28. February 2013 05:32

The shebang portion of the Python code also uses #!/usr/bin/python; is this correct?


answer - no, that's for Linux -

CGI Method in detail:

The standard CGI method applies to most scripting languages when they are not loaded as an Apache module (PHP usually is an Apache module). The two big scripting languages that fit this bill are Perl & Python. I should say that almost ANY executable on a server can be run in this mode, it does not have to be a scripting language.

CGI language support comes down to three elements:

A. The language can be installed separately. So you don't have to use the Perl that comes with XAMPP, you could use Strawberry or ActiveStates - or in your case, install Python standalone. Python.org or ActiveStates - also has Python.

B. Location of scripts: CGI is for Common Gateway Interface. In Apache, its the 'ScriptAlias' folder - usually '/cgi-bin'. Every script that works with CGI goes in that folder.

C. Shebang Line: The first line in every CGI script must be the path to the language executable. If the language executable is in the ServerRoot, it can be a relative path. If it is outside the ServerRoot, it should be the complete filesystem path (including drive if on Windows) and the exectable's file name such as "c:\perl\bin\perl.exe"

From one of my installs (for Strawberry Perl) -

Code: Select all
#! "C:\strawberry\perl\bin\perl.exe"


http://en.wikipedia.org/wiki/Common_Gateway_Interface

Good Luck
:)
User avatar
JonB
AF Moderator
 
Posts: 3210
Joined: 12. April 2010 16:41
Location: Land of the Blazing Sun
Operating System: Windows XP/7 - Fedora 15 1.7.7

Re: Using Python with XAMPP

Postby Nobbie » 28. February 2013 14:00

hackattack142 wrote:Hello,

Per the Python documentation, which you should take a look at to see the various options, (http://docs.python.org/2/howto/webservers.html) CGI is no longer recommended.


I do not agree to this "documentation", the (poor) arguments contra CGI are kind of childish. Of course, if someone makes an error somewhere, things are going wrong. This is the same thing for everyhing concerning the configuration of a webserver.

Configuring Python as CGI and running as CGI is one of the easiest things when configuring a webserver. Anyway, usually this is a task for a well educated Administrator. He will definately laugh if he reads this "funny" arguments contra CGI.

On the other hand, the goal of Xampp is to give non-educated people the opportunity, to install a webserver environment for development as easyly as possible, as this usually is a task for well educated Admins (s. above). It is definately a horrible pain for these non-educated people, to install a full development environment for C and Apache Modules and try to "make" their own build of a mod_wsgi from a tarball or similar. This is a billion times more difficult (especially on Windows) than simply running Python in CGI Mode (what works like a charm for many many years). It is even the same pain to look for a matching precompiled version, which does not collide with the Xampp binarys due to to different C Compilers, Apache Versions etc.

hackattack142 wrote:It recommends you use WSGI (see mod_wsgi at https://code.google.com/p/modwsgi/).


As long as this module is not part of a Xampp installation, this cant be a valid recommendation.
Nobbie
 
Posts: 13170
Joined: 09. March 2008 13:04

Re: Using Python with XAMPP

Postby ollybenson » 08. November 2013 13:42

Hi,

Just because I wanted to do this and the instructions weren't very clear.

1. Install Python from python.org (I'm using Python 3.3)
2. In the apache cgi-bin put a file called helloworld.py that says: (obviously change the filepath to the python.exe that you've installed)
Code: Select all
#!"C:\python33\python.exe"
print ("Content-Type: text/html\n")
print ('Hello World')

3. Go to http://localhost/cgi-bin/helloworld.py - you should see it say Hello World!

Olly
ollybenson
 
Posts: 1
Joined: 08. November 2013 13:38
Operating System: Windows 7


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 110 guests