I\'ve got a background in PHP, dotNet and am charmed by Python. I want to transpose functionality from PHP to Python step by step, running bits and pieces side-by-side. Duri
I just did this in 5 minutes.
Insure you have IIS. run: %windir%\system32\OptionalFeatures.exe
. Or, via pointy-clicky: Start...Control Panel...Programs and Features... (and then on the left hand side) Turn Windows Features on or Off. Make sure CGI is installed, under the IIS node.
Download Python for Windows, from python.org . I grabbed Python2.7. Make sure you get the x64 version if you have an x64 version of Windows.
Unpack and install that python MSI. Choose the default, which puts python into c:\Python27
Create a directory to hold your "development" python scripts. Eg, c:\dev\python
Set the permissions on the files in the directory c:\dev\python
to allow IIS to read and execute. Do this by running these two icacls.exe commands from the command line:
cd \dev\python
icacls . /grant "NT AUTHORITY\IUSR:(OI)(CI)(RX)"
icacls . /grant "Builtin\IIS_IUSRS:(OI)(CI)(RX)"
Open IIS manager. Run %windir%\system32\inetsrv\iis.msc
, or do this via the control panel: Start...Control Panel...Administrative Tools...Internet Information Services (IIS) Manager. Create a new application. Specify the virtual path as /py
and the physical path as c:\dev\python
.
Within that IIS application, add a script map for *.py
, and map it to c:\python27\python.exe %s %s
create a "HelloWorld.py" file in c:\dev\python
with this as the content:
print('Content-Type: text/plain')
print('')
print('Hello, world!')
invoke http://localhost/py/helloworld.py
just make sure the path to the directory holding the cgi scripts doesn't have spaces or &.
i tried lots of things for many days and nothing worked then i changed the path and it worked
UPDATE:
If it has spaces, put quotes around the path, but not the %s %s
like this:
"C:\Program Files\Python36\python.exe" %s %s
When you are developing a web application with Python, you don't use IIS/Apache/etc. Those web servers are only for deployment. Frameworks like Pyramid/Pylons/Django all come with built-in web servers. Pyramid, in particular, has excellent documentation which should help you to get started: http://docs.pylonsproject.org/docs/pyramid.html
When you get to the point of deployment, Linux + Apache would be a much saner choice than Windows + IIS. If you absolutely must use Windows + IIS, don't use isapi-wsgi, as it has phantom performance problem: http://groups.google.com/group/isapi_wsgi-dev/browse_thread/thread/9fade6efca6c5b89
PyISAPIe has worked well enough for me, but I had to compile my own PyISAPIe.dll for Python 2.7.