Python on IIS: how?

后端 未结 3 1393
隐瞒了意图╮
隐瞒了意图╮ 2020-11-29 15:25

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

相关标签:
3条回答
  • 2020-11-29 16:01

    I just did this in 5 minutes.

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

      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:\dev\python

    5. 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)"
      
    6. 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.

      enter image description here

      enter image description here

    7. Within that 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

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

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

    0 讨论(0)
  • 2020-11-29 16:15

    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

    0 讨论(0)
  • 2020-11-29 16:16

    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.

    0 讨论(0)
提交回复
热议问题