【问题标题】:Python not working in Linux shared hosting serverPython 在 Linux 共享托管服务器中不起作用
【发布时间】:2014-05-11 21:48:13
【问题描述】:

我试图在我的 Linux 共享托管服务器中将 python 设置为脚本语言。我已关注this link 在我的服务器中设置 python 2.6.4

我已经按照与那里相同的步骤进行操作,一切正常,但我仍然无法执行 python 文件。

例如:

我在public_html/index.py 下创建了一个文件,代码如下

#!/home/explore/bin/python

print "Content-Type: text/html\n"

print "Hello World!"

但是当我在浏览器中打开这个文件时,它只是简单的文本。

请帮忙

【问题讨论】:

  • 尝试首先使用/home/explore/bin/python index.py 运行您的脚本,看看是否可行。
  • SyntaxError: invalid syntax index.py , line 1
  • 为什么要安装过时的版本?如果您真的想要 Python 2,那么您绝对应该考虑使用 2.7 进行新部署。

标签: python linux


【解决方案1】:

你的脚本第一行写得不好……那行被称为shebang,这是人类可读的magic number 来识别脚本:

#!/home/explore/bin/python

she(源自 shahash)代表井号:#

然后按感叹号:!

【讨论】:

  • 感谢您的更正,但我仍然只能在 Shell 终端中看到输出,而在浏览器中看不到
  • 好吧,它超出了堆栈溢出的范围,而且您没有提供足够的信息来获得帮助。请在Server Fault那里再次提问,告诉您什么是托管服务,什么是您的网络服务器,以及您如何在问题中配置您的网络服务器。
  • /home/explore/bin/python index.py 这给了我错误找不到文件,所以我正在使用/home/explore/bin/python /home/explore/public_html/index.py
猜你喜欢
  • 2012-07-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多