How to setup and run Python on Wampserver?

2019-04-06 04:14发布

问题:

Can anyone help me to set up Python to run on Wampserver. From what I've read so far you would need to use a combination of Wampser, Python, mod_pyhton, and adjustment to the Apache http.conf file. I've tried it but i belive i am having conflict when it comes to versions. Does anyone know of a cobination of versions that can work so that i can do some local python development using my wampserver? Links to the download would be greatly appreciated.

My current config: Wampserver 2.0c => Apache Version : 2.2.8 , PHP Version : 5.2.6 , MySQL Version : 5.0.51b

回答1:

Do not use mod_python; it does not do what most people think it does. Use mod_wsgi instead.



回答2:

How about using web.py (download) or django?

They have their own web server, and you can also connect MySQL server with MySQLdb extension.



回答3:

Recognising that the post asks about mod_python, I'm posting the following, in case using CGI is acceptable.

It has been a while since I got this to work, but I got CGI scripts written with Python to run under Wampserver with a couple simple things (although it didn't seem simple at the time):

  • Download and install Python if you haven't already. The standard install should let you run programs from a command prompt (which you'll need).
  • Write your Python CGI program, making the first line be #!python (or the full path to the python executable). While the first line isn't usually necessary for Python programs under Windows, Apache seems to need this so it knows the program is Python.
  • Place the program in your cgi-bin directory.

That should do it. I double checked my httpd.conf file and don't see any changes to get Python working. (This assumes you already have CGI working otherwise.)

The following simple script should tell you if you have things working:

#!python
print "Content-type: text/html"
print ""
print "<html>"
print "<head>"
print "<title>CGI Test of Python</title>"
print "</head>"
print "<body>"
print "This is a test"
print "</body>"
print "</html>"


回答4:

Here are some instructions here: http://www.imladris.com/Scripts/PythonForWindows.html



回答5:

My WSGI setup made on WAMP server 2.5, 32bits (Apache 2.4.9 32bits) with PythonWin 2.7.8 (default, Jul 2 2014, 19:50:44) [MSC v.1500 32 bit (Intel)] on win32 went on the next way.

WAMP route = C:/wamp/

Config Apache

Download 32bits mod_wsgi.so from http://www.apachelounge.com/viewtopic.php?t=5143 and place it as c:\wamp\bin\apache\apache2.4.9\modules\mod_wsgi.so

Load the wsgi module to apache in the main C:\wamp\bin\apache\apache2.4.9\conf\httpd.conf:

LoadModule wsgi_module modules/mod_wsgi.so 
WSGIScriptAlias /API c:/wamp/www/API/code.py 

Get webpy

C:\tmp>git clone git://github.com/webpy/webpy.git
C:\tmp>python webpy\setup.py install

Test it:

C:\tmp>python
ActivePython 2.7.8.10 (ActiveState Software Inc.) based on 
Python 2.7.8(default, Jul  2 2014, 19:50:44) [MSC v.1500 32 bit (Intel)] 
on win32  Type "help", "copyright", "credits" or "license" for more information.
>>> import web
>>>

Create your application as c:\wamp\www\API\code.py

import web
urls = (
  '', 'root',
  '/(.*)', 'hello',
  )

class root:
    def GET(self):
        return "This is the root URI."

class hello:
    def GET(self, name):
        return "Hello %s from webPy." % name

application = web.application(urls, globals()).wsgifunc()

Result

Restart your apache webserver and check http://localhost/API



回答6:

Step 1: Download the Python Setup https://www.python.org/downloads/release/python-350/

Step 2: Install Python

Step 3: Download the wampserver https://sourceforge.net/projects/wampserver/files/WampServer%202/Wampserver%202.4/

Step 4: Open httpd.conf file in notepad,from that location C:\wamp64\bin\apache\apache2.4.23\conf\httpd.conf

Step 5: find CTRL+F "Directory" in httpd.conf and set wamp install location in Document and Directory , where your wamp server is installed , kindly use forward slash "/" not backword "\"

A.(DocumentRoot "C:/wamp64/www")

B.(Directory "C:/wamp64/www"> )

and Replace these two line inside Directory "C:/wamp64/www">

Remove:-

Options Indexes FollowSymLinks

Add:-

AddHandler cgi-script .cgi .py

Options Indexes FollowSymLinks ExecCGI

C. Set cgi-bin location

(Directory "C:/wamp64/cgi-bin" AllowOverride None Options None...)

Step 6: Restart All Service of wamp.

Step 7: make python program but add these line at first

#!D:/paython installed/python.exe // set path where python is installed

Step 8: save program .py extension.

Step 9: run on browser using

 localhost/file_name.py


回答7:

Wampserver doesn't have addon for python/django, but XAMPP does.

A good tutorial here:

http://jyotirmaya.blogspot.com/2008/11/xampp-python-django.html