Python on IIS: how?

I have background in PHP, dotNet and fascinated by Python. I want to gradually transfer functionality from PHP to Python, using bits and pieces side by side. During this transition, which may take 2 years from the moment the application is huge, I am tied to IIS. I have 15 years of web programming experience, including some C working in the IIS ISAPI module, which is the job that I no longer want to dive into.

Python seems to just not work on IIS. I struggled with FastCGI (not supported, only for PHP) and PyIsapie (poorly documented, could not start and run it). As a result, I got it and worked with the HeliconZoo BUT dll:

My next problem: how to debug / develop the site? In PHP, you install a debugger and whenever you have problems on your website, you just debug it, set a breakpoint, look at the code, check the clock, etc. It seems to me that this is the most rudimentary kind of developer work or troubleshooting. I bought WingIDE, which is a great tool and debugger, but for some reason it cannot connect to the Python instance in the IIS process, so there is no debugging. I noticed that Helicon runs Python with -O , so I even recompiled Python to ignore this flag altogether, but my debugger (WingIDE) just won't appear.

I can set up the PHP hello world website on IIS in half an hour, including loading time. I think I spent about 120 hours or more to get this working in Python to no avail. I bought Python Programming and Learning Python, which is about 3,000 pages. And I googled until I fell.

I think Python is a great language, but I'm on the verge of interrupting my attempts. Is there anyone who can give me step-by-step instructions on how to configure this on IIS7?

+48
python iis
Jul 25 '11 at 22:47
source share
3 answers

I just did it in 5 minutes.

  • Make sure you have IIS. run: %windir%\system32\OptionalFeatures.exe . Or through pointy-clicky: Get started ... Control Panel ... Programs and Features ... (and then on the left) Turn Windows features on or off. Make sure CGI is installed under the IIS node.

    enter image description here

  • Download Python for Windows from python.org. I grabbed Python2.7. Make sure you get the x64 version if you have the x64 version for Windows installed.

  • Unzip and install this MSI python. Choose the default value that puts python in c:\Python27

  • Create a directory in which your "development" of python scripts will be stored. For example, c:\dev\python

  • Set permissions for files in the c:\dev\python so that IIS can 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 it through the control panel: Start ... Control Panel ... Administrative %windir%\system32\inetsrv\iis.msc ... Internet Information Services (IIS) Manager. Create a new application. Specify the virtual path as /py and the physical path as c:\dev\python .

    enter image description here

    enter image description here

  • In this IIS application, add a script map for *.py and map it to c:\python27\python.exe %s %s

    enter image description here

    enter image description here

    enter image description here

  • create the file "HelloWorld.py" in c:\dev\python with this as content:

     print('Content-Type: text/plain') print('') print('Hello, world!') 
  • invoke http://localhost/py/helloworld.py

+111
Mar 16 2018-12-12T00:
source share

When you are developing a web application with Python, you are not using IIS / Apache / etc. These web servers are for deployment only. Frames like Pyramid / Pylons / Django have built-in web servers. The pyramid in particular has excellent documentation that should help you get started: http://docs.pylonsproject.org/docs/pyramid.html

When you get to the deployment point, Linux + Apache will be a much smarter choice than Windows + IIS. If you absolutely must use Windows + IIS, do not use isapi-wsgi, as it has phantom performance problems: http://groups.google.com/group/isapi_wsgi-dev/browse_thread/thread/9fade6efca6c5b89

PyISAPIe works well enough for me, but I had to compile my own PyISAPIe.dll for Python 2.7.

+1
Jul 26 2018-11-11T00:
source share

just make sure the path to the directory containing the cgi scripts does not have spaces or &.

I tried many things many times and nothing worked, then I changed the path and it worked

+1
Aug 23 '14 at 13:00
source share



All Articles