简体   繁体   English

如何在Windows上安装Python for Apache?

[英]How to install Python for Apache on Windows?

I'm looking for the fast, easy (all default settings) way of installing Python on my windows machine so that Apache can use it. 我正在寻找在我的Windows机器上安装Python的快速,简单(所有默认设置)方式,以便Apache可以使用它。 I currently have a Windows 7 installation with Apache and PHP working. 我目前使用Apache和PHP工作的Windows 7安装。 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. 我想尝试用Python制作一些简单的网页,只是为了一点点玩Python并学习一两件事。 I downloaded and installed Python 3.2 Python 2.7.2 (As advised below). 我下载并安装了 Python 3.2 Python 2.7.2(如下所述)。 What do I do next? 接下来我该怎么办? I would like to make a "Hello World". 我想制作一个“Hello World”。 Do I need mod_python or can I do without? 我需要mod_python还是可以不使用? I assume I need to tell Apache somehow that Python is available. 我假设我需要以某种方式告诉Apache Python是否可用。 I probably need to make an "index.py" file, or something similar? 我可能需要制作一个“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: 基本上我正在寻找Python的等效以下PHP脚本在我的Apache中工作:

<html>
 <head>
  <title>Hello World</title>
 </head>
 <body>
  <?= "Hello World"; ?>
 </body>
</html>

First of all, especially in the web sector it's better to stay with python 2 (2.7) for now. 首先,特别是在Web领域,最好继续使用python 2(2.7)。 Lots of frameworks and libraries are not py3-ready yet. 许多框架和库尚未准备就绪。

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. 最后,与PHP不同,编写python web应用程序通常不是一个好主意,它的思想是文件和URL之间的1:1映射。 To get started with something nice, have a look at the Flask microframework . 要开始使用好的东西,请查看Flask微框架 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. 为了使它更好,你在开发过程中不需要Apache,因为你可以简单地运行一个基于python的developmont服务器。

You can use mod_python (deprecated and not recommended) or better mod_wsgi . 您可以使用mod_python(已弃用且不推荐)或更好的mod_wsgi

Look at: 看着:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM