如何在 Windows 上为 Apache 安装 Python?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7157565/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to install Python for Apache on Windows?
提问by Bazzz
I'm looking for the fast, easy (all default settings) way of installing Python on my windows machine so that Apache can use it. I currently have a Windows 7 installation with Apache and PHP working. I want to try and make some simple web pages in Python, just to play around with Python for a bit and learn a thing or two. I downloaded and installed Python 3.2Python 2.7.2 (As advised below). What do I do next? I would like to make a "Hello World". Do I need mod_python or can I do without? I assume I need to tell Apache somehow that Python is available. I probably need to make an "index.py" file, or something similar?
我正在寻找在我的 Windows 机器上安装 Python 的快速、简单(所有默认设置)方式,以便 Apache 可以使用它。我目前有一个 Windows 7 安装,Apache 和 PHP 工作正常。我想尝试用 Python 制作一些简单的网页,只是为了玩一会 Python 并学习一两件事。我下载并安装了Python 3.2Python 2.7.2(如下所述)。我接下来该怎么做?我想做一个“Hello World”。我需要 mod_python 还是不需要?我假设我需要以某种方式告诉 Apache Python 可用。我可能需要制作一个“index.py”文件或类似的文件?
I'm not directly looking for tutorials on the Python language itself, but just for some steps to make the simplest of the simplest script (Hello World) work on my current system.
我不是直接在寻找关于 Python 语言本身的教程,而是为了让最简单的脚本(Hello World)在我当前的系统上工作的一些步骤。
Basically I'm looking for the Python equivalent of the following php script to work in my Apache:
基本上,我正在寻找与以下 php 脚本等效的 Python 脚本以在我的 Apache 中工作:
<html>
<head>
<title>Hello World</title>
</head>
<body>
<?= "Hello World"; ?>
</body>
</html>
采纳答案by Xaerxess
You can use mod_python (deprecated and not recommended) or better mod_wsgi
.
您可以使用 mod_python(已弃用且不推荐)或更好的mod_wsgi
。
Look at:
看着:
Django docs - How to use Django with Apache and mod_wsgi- the information is sufficient to set up Apache and mod_wsgi.
this questionthere, where there is an example of setting up
mod_wsgi
using cherrypy.
Django docs - How to use Django with Apache and mod_wsgi- 信息足以设置 Apache 和 mod_wsgi。
这个问题在那里,那里有一个
mod_wsgi
使用cherrypy设置的例子。
回答by ThiefMaster
First of all, especially in the web sector it's better to stay with python 2 (2.7) for now. Lots of frameworks and libraries are not py3-ready yet.
首先,尤其是在 Web 领域,现在最好使用 python 2 (2.7)。许多框架和库还没有准备好 py3。
Then you might want to use mod_wsgi instead of mod_python which is deprecated and not available in binary form for recent python versions (and using old python versions such as 2.5 is bad).
然后你可能想要使用 mod_wsgi 而不是 mod_python,它已被弃用,并且在最近的 python 版本中不能以二进制形式使用(并且使用旧的 python 版本,例如 2.5 是不好的)。
Finally, unlike PHP it's usually not a good idea to write python webapplications with the idea of 1:1 mappings between files and urls. To get started with something nice, have a look at the Flask microframework. It has some good examples and a full tutorial. And to make it even better, you don't need Apache for it during development as you can simply run a python-based developmont server.
最后,与 PHP 不同的是,使用文件和 url 之间 1:1 映射的想法来编写 python web 应用程序通常不是一个好主意。要开始使用一些不错的东西,请查看Flask 微框架。它有一些很好的例子和一个完整的教程。为了让它变得更好,您在开发过程中不需要 Apache,因为您可以简单地运行基于 python 的 developmont 服务器。