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. During this transition, which could take 2 years since the app is enormous, I am bound to IIS. I’ve got 15 years background of web-programming, including some C work in an ISAPI module on IIS which is the kind of work I don’t want to dive into any more.
It seems Python just doesn’t run well on IIS. I’ve struggled with FastCGI (not supported, just for PHP) and
PyIsapie (badly documented, couldn’t get it up and running). In the end I got it up and running with a HeliconZoo dll BUT:
My next problem is: how to debug/develop a site? In PHP you install a debugger and whenever you have a problem in your website, you just debug it, set a breakpoint, step through code, inspect watches and such. It seems to me this is the most rudimentary type of work for a developer or troubleshooter. I’ve bought WingIDE which is an excellent tool and debugger but it can’t hook into the Python instance in the IIS process for some reason so no debugging. I noticed Helicon starts Python with
-O so I even recompiled Python to ignore this flag altogether but my debugger (WingIDE) just won’t come up.
I can set up a PHP ‘hello world’ website on IIS in half an hour including download time. I think I’ve spent about 120 hours or more getting this to work for Python to no avail. I’ve bought Programming Python and Learning Python which is about 3000 pages. And I’ve googled until I dropped.
I think Python is a great language but I’m on the verge of aborting my attempts. Is there anyone who can give me a step-by-step instruction on how to set this up on IIS7?
I just did this in 5 minutes.
Insure you have IIS. run:
%windir%system32OptionalFeatures.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
Create a directory to hold your “development” python scripts. Eg,
Set the permissions on the files in the directory
c:devpythonto allow IIS to read and execute. Do this by running these two icacls.exe commands from the command line:
cd devpython icacls . /grant "NT AUTHORITYIUSR:(OI)(CI)(RX)" icacls . /grant "BuiltinIIS_IUSRS:(OI)(CI)(RX)"
Open IIS manager. Run
%windir%system32inetsrviis.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
/pyand the physical path as
Within that IIS application, add a script map for
*.py, and map it to
c:python27python.exe %s %s
create a “HelloWorld.py” file in
c:devpythonwith this as the content:
print('Content-Type: text/plain') print('') print('Hello, world!')
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
If it has spaces, put quotes around the path, but not the
"C:Program FilesPython36python.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.