python 在 iis 中的安装过程

一、下载 https://www.python.org/
    下载 python-3.10.2-amd64.exe 后点击安装即可。

二、输入 python 命令,如下提示,说明正常:
C:\Users\ASUS>python
Python 3.10.2 (tags/v3.10.2:a58ebcc, Jan 17 2022, 14:12:15) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.


三、安装 wfastcgi,若不设置环境变量,直接在CMD下运行下面路径
D:\ProgramFiles\Python\Python310\Scripts pip install wfastcgi

 

例如:
D:\ProgramFiles\Python\Python310\Scripts>pip install wfastcgi
Collecting wfastcgi
  Downloading wfastcgi-3.0.0.tar.gz (14 kB)
Using legacy 'setup.py install' for wfastcgi, since package 'wheel' is not installed.
Installing collected packages: wfastcgi
    Running setup.py install for wfastcgi ... done
Successfully installed wfastcgi-3.0.0
WARNING: You are using pip version 21.2.4; however, version 22.0.4 is available.
You should consider upgrading via the 'D:\ProgramFiles\Python\Python310\python.exe -m pip install --upgrade pip' command.

D:\ProgramFiles\Python\Python310\Scripts>

四、web.config 中添加如下代码:
    或者 IIS - webdir - 处理程序映射 - 添加模块映射:
    1. 请求路径(P):*.py
    2. 可执行文件:D:\ProgramFiles\Python\Python310\python.exe %s %s

<handlers>
    <add resourceType="File" verb="*" modules="CgiModule" name="Python310" path="*.py" scriptProcessor="D:\python\python.exe %s %s"  />
    <add resourceType="File" verb="*" modules="FastCgiModule" name="php-7233" path="*.php" scriptProcessor="D:\php\7233\php-cgi.exe" />
</handlers>


五、简单运行测试,将下面代码 保存为 hello.py 文件:

#!/usr/bin/python
def launcher():
    import io
    import sys
    import urllib.request
    print ('Content-type: text/html\n')
    sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='utf8')
    with urllib.request.urlopen('https://docs.python.org/3/library/urllib.request.html') as f:
        print(f.read().decode('utf-8'))

launcher()

六、浏览器输入 http://localhost/hello.py 将获得URL页面代码,类似于执行 view-source:https://docs.python.org/3/library/urllib.request.html。

经过以上简单配置,在 Windows 上的 IIS 中可以运行三种服务器端语言:PHP ASP.NET Python

Python 3.10.2 documentation: https://docs.python.org/3/library/urllib.request.html

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐