Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
128 views
in Technique[技术] by (71.8m points)

Python on IIS: how?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I just did this in 5 minutes.

  1. 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.

    enter image description here

  2. 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.

  3. Unpack and install that python MSI. Choose the default, which puts python into c:Python27

  4. Create a directory to hold your "development" python scripts. Eg, c:devpython

  5. Set the permissions on the files in the directory c:devpython to 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)"
    
  6. 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 /py and the physical path as c:devpython.

    enter image description here

    enter image description here

  7. Within that IIS application, add a script map for *.py, and map it to c:python27python.exe %s %s

    enter image description here

    enter image description here

    enter image description here

  8. create a "HelloWorld.py" file in c:devpython with this as the content:

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...