Python 如何使py脚本在Wamp上可执行
我在WAMP上尝试通过Apache运行python时遇到文件不可执行错误。以下是访问日志中的错误消息:Python 如何使py脚本在Wamp上可执行,python,apache,wamp,Python,Apache,Wamp,我在WAMP上尝试通过Apache运行python时遇到文件不可执行错误。以下是访问日志中的错误消息: [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] [pi
[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>
DocumentRoot“c:/wamp/www”
AddHandler cgi script.cgi.py
#
#选项指令的可能值为“无”、“全部”,
#或以下任何组合:
#索引包括以下符号链接符号链接所有者匹配执行CGI多视图
#
#请注意,“多视图”必须显式命名为*--“所有选项”
#不给你。
#
#期权指令既复杂又重要。请看
# http://httpd.apache.org/docs/2.4/mod/core.html#options
#了解更多信息。
#
选项索引跟随SYMLINKS ExecCGI
#选项+索引后跟符号链接+执行CGI
#
#AllowOverride控制可在.htaccess文件中放置的指令。
#它可以是“全部”、“无”或关键字的任意组合:
#AllowOverride文件信息AuthConfig限制
#
允许超越所有
#
#控制谁可以从此服务器获取内容。
#
#要求所有授权
#onlineoffline标记-不删除
命令拒绝,允许
全盘否定
允许从127.0.0.1开始
允许来自::1
允许从本地主机
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>"
#!C:\Python32\python.exe
打印“内容类型:文本/html”
打印“”
打印“”
打印“”
打印“Python1的CGI测试”
打印“”
打印“”
打印“这是一个测试”
打印“”
打印“”
cgi模块已经启用。但这是谷歌的第一个链接。因此,只需在#之后添加空格即可!它应该看起来像“#!c:\blabla”,而不是“#!c:\blabla”。仅此而已。您是否遵循错误消息并确保第一行脚本中有有效的shebang?我正在使用“!”正如许多示例中所示,指向Python文件夹。你在这里指的是什么,@Nabla?这可能有助于@riggsfully我不知道它是如何解决我的问题的?@Volatil3这个shebang肯定是
#
后面是python可执行文件的路径,而不是python文件夹。在#!之后不需要空格!。