如何在Wamp上生成py脚本

时间:2014-01-16 19:09:36

标签: python apache wamp

尝试在WAMP上通过Apache运行python时,我收到文件不可执行错误。以下是access_log中的错误消息:

[Fri Jan 17 00:31:57.358375 2014] [cgi:error] [pid 2972:tid 612] [client 127.0.0.1:3495] script not found or unable to stat: C:/wamp/www/python.py
[Fri Jan 17 00:32:26.483375 2014] [win32:error] [pid 2972:tid 612] [client 127.0.0.1:3496] AH02102: C:/wamp/www/python.py is not executable; ensure interpreted scripts have "#!" or "'!" first line
[Fri Jan 17 00:32:26.483375 2014] [cgi:error] [pid 2972:tid 612] (9)Bad file descriptor: [client 127.0.0.1:3496] AH01222: don't know how to spawn child process: C:/wamp/www/python.py
[Fri Jan 17 00:32:29.327125 2014] [win32:error] [pid 2972:tid 612] [client 127.0.0.1:3497] AH02102: C:/wamp/www/python.py is not executable; ensure interpreted scripts have "#!" or "'!" first line
[Fri Jan 17 00:32:29.327125 2014] [cgi:error] [pid 2972:tid 612] (9)Bad file descriptor: [client 127.0.0.1:3497] AH01222: don't know how to spawn child process: C:/wamp/www/python.py

的httpd.conf

DocumentRoot "c:/wamp/www"
<Directory "c:/wamp/www">
    AddHandler cgi-script .cgi .py
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks ExecCGI
    #Options +Indexes FollowSymLinks +ExecCGI

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   AllowOverride FileInfo AuthConfig Limit
    #
    AllowOverride All

    #
    # Controls who can get stuff from this server.
    #
#    Require all granted
#   onlineoffline tag - don't remove
     Order Deny,Allow
     Deny from all
     Allow from 127.0.0.1
     Allow from ::1
     Allow from localhost
</Directory>

py文件

#!C:\Python32\python.exe

print "Content-type: text/html"
print ""
print "<html>"
print "<head>"
print "<title>CGI Test of Python1</title>"
print "</head>"
print "<body>"
print "This is a test"
print "</body>"
print "</html>"

cgi模块已经启用。

1 个答案:

答案 0 :(得分:-1)

Necropost但这是第一个链接谷歌。所以你只需要在#之后添加空间!它应该看起来像“#!c:\ blablabla”而不是“#!c:\ blablabla”。这就是全部。