【问题标题】:How to make a py script executable on Wamp如何使 py 脚本在 Wamp 上可执行
【发布时间】:2014-02-05 21:16:28
【问题描述】:

尝试在 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 模块已启用。

【问题讨论】:

  • 您是否遵循了错误消息并确保第一行脚本中存在有效的 shebang?
  • 我正在使用“!”正如在许多示例中找到指向 Python 文件夹的那样。 @Nabla 你在这里指的是什么?
  • @RiggsFolly 我不知道它如何解决我的问题?
  • @Volatil3 shebang 必须是#!,后跟 python 可执行文件的路径,而不是 python 文件夹。

标签: python apache wamp


【解决方案1】:

Necropost 但这是谷歌的第一个链接。所以你只需要在#之后添加空格!它应该看起来像 "#!c:\blablabla" 而不是 "#!c:\blablabla"。仅此而已。

【讨论】:

  • #! 之后不需要空格。
猜你喜欢
  • 1970-01-01
  • 2019-03-19
  • 1970-01-01
  • 2016-08-02
  • 1970-01-01
  • 1970-01-01
  • 2018-12-16
  • 2011-05-13
  • 1970-01-01
相关资源
最近更新 更多