IIS 上的 Python:如何? [英] Python on IIS: how?

查看:14
本文介绍了IIS 上的 Python:如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 PHP 和 dotNet 的背景,并且对 Python 着迷.我想一步一步地将功能从 PHP 转换到 Python,并排运行点点滴滴.在这个过渡期间,由于应用程序非常庞大,可能需要 2 年的时间,我必须使用 IIS.我有 15 年的网络编程背景,包括在 IIS 上的 ISAPI 模块中从事一些 C 工作,我不想再深入研究这类工作.

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.

看来 Python 在 IIS 上运行得不好.我一直在努力使用 FastCGI(不支持,仅适用于 PHP)和 PyIsapie(记录错误,无法启动和运行).最后,我使用 HeliconZoo dll 启动并运行它:

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:

我的下一个问题是:如何调试/开发网站?在 PHP 中,你安装了一个调试器,当你的网站出现问题时,你只需调试它,设置断点,单步执行代码,检查手表等等.在我看来,这是开发人员或故障排除人员最基本的工作类型.我已经购买了 WingIDE,它是一个出色的工具和调试器,但由于某种原因它无法连接到 IIS 进程中的 Python 实例,因此无法进行调试.我注意到 Helicon 用 -O 启动 Python,所以我什至重新编译 Python 以完全忽略这个标志,但我的调试器 (WingIDE) 不会出现.

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.

我可以在包括下载时间在内的半小时内在 IIS 上建立一个 PHP 'hello world' 网站.我想我已经花了大约 120 个小时或更长时间来让它为 Python 工作但无济于事.我买了Programming PythonLearning Python,大约有3000 页.我一直在谷歌搜索直到我放弃.

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.

我认为 Python 是一种很棒的语言,但我即将放弃我的尝试.有没有人可以给我一个关于如何在 IIS7 上进行设置的分步说明?

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?

推荐答案

我只用了 5 分钟就搞定了.

I just did this in 5 minutes.

  1. 确保您有 IIS.运行:%windir%system32OptionalFeatures.exe.或者,通过点按:开始...控制面板...程序和功能...(然后在左侧)打开或关闭 Windows 功能.确保在 IIS 节点下安装了 CGI.

  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.

从 python.org 下载适用于 Windows 的 Python.我抓住了 Python2.7.如果您使用的是 x64 版本的 Windows,请确保获得 x64 版本.

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.

解压并安装那个python MSI.选择默认值,将 python 放入 c:Python27

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

创建一个目录来保存您的开发"python 脚本.例如,c:devpython

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

设置c:devpython目录下文件的权限,允许IIS读取和执行.通过从命令行运行这两个 icacls.exe 命令来执行此操作:

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)"

  • 打开 IIS 管理器.运行 %windir%system32inetsrviis.msc,或通过控制面板执行此操作:开始...控制面板...管理工具...Internet 信息服务 (IIS) 管理器.创建一个新应用程序.将虚拟路径指定为 /py,将物理路径指定为 c:devpython.

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

    在该 IIS 应用程序中,为 *.py 添加脚本映射,并将其映射到 c:python27python.exe %s %s

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

    c:devpython 中创建一个HelloWorld.py"文件,内容如下:

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

    print('Content-Type: text/plain')
    print('')
    print('Hello, world!')
    

  • 调用http://localhost/py/helloworld.py

    这篇关于IIS 上的 Python:如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆