在 Windows 平台上的 Xampp 上运行 Python 代码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5164921/
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
Running Python Code on Xampp on windows platform
提问by csguy11
XAMPP-PYTHON-WINDOWS
XAMPP-Python-WINDOWS
I have installed Xampp. I'm running the apache web server and mySql service. I want to host my python code on my web server. However, I am having a hard time setting up python with Xampp. I read about modwsgi, downloaded it and pasted it in the modules folder. I have python 3.2 installed on my C drive.
我已经安装了 Xampp。我正在运行 apache 网络服务器和 mySql 服务。我想在我的网络服务器上托管我的 python 代码。但是,我很难用 Xampp 设置 python。我阅读了有关 modwsgi 的信息,将其下载并粘贴到模块文件夹中。我的 C 驱动器上安装了 python 3.2。
Please let me know what should I do next, as in where should i paste my python files and how should I execute them through a web browser? I should be able to do this:
请让我知道我接下来应该做什么,比如我应该在哪里粘贴我的 python 文件以及我应该如何通过网络浏览器执行它们?我应该能够做到这一点:
http://74.xxx.xxx.xx/python/test.py(localhost/python/test.py)
http://74.xxx.xxx.xx/python/test.py(localhost/python/test.py)
and this should execute the python code.
这应该执行python代码。
When I try to do the above, i get this:
当我尝试执行上述操作时,我得到了以下信息:
Server error!
服务器错误!
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script.
服务器遇到内部错误,无法完成您的请求。服务器过载或 CGI 脚本中存在错误。
If you think this is a server error, please contact the webmaster.
如果您认为这是服务器错误,请联系网站管理员。
Error 500
错误 500
74.194.129.16 3/2/2011 2:11:16 AM Apache/2.2.17 (Win32) mod_ssl/2.2.17 OpenSSL/0.9.8o PHP/5.3.4 mod_perl/2.0.4 Perl/v5.10.1
74.194.129.16 3/2/2011 2:11:16 AM Apache/2.2.17 (Win32) mod_ssl/2.2.17 OpenSSL/0.9.8o PHP/5.3.4 mod_perl/2.0.4 Perl/v5.10.1
All the help is highly appreciated.
非常感谢所有的帮助。
回答by Graham Dumpleton
The official releases of mod_wsgi don't support Python 3.2 so you cant use it. To use Python 3.2 you would need to compile mod_wsgi from source code in subversion repository which I would suggest is probably going to be a bit beyond what you are able to do based on problems you are having above. So, use Python 2.6/2.7. Also see:
mod_wsgi 的官方版本不支持 Python 3.2,所以你不能使用它。要使用 Python 3.2,您需要从 subversion 存储库中的源代码编译 mod_wsgi,我建议这可能会超出您根据上述问题所能做的范围。因此,请使用 Python 2.6/2.7。另见:
http://code.google.com/p/modwsgi/wiki/InstallationOnWindowshttp://code.google.com/p/modwsgi/wiki/DownloadTheSoftware?tm=2#Windows_Binary_Downloads
http://code.google.com/p/modwsgi/wiki/InstallationOnWindows http://code.google.com/p/modwsgi/wiki/DownloadTheSoftware?tm=2#Windows_Binary_Downloads
As Daniel suggested I would suggest you use Flask. You could also use web2py which is another framework which is easy for newbies. I would also suggest that if you are only starting to learn this stuff that you not use Apache/mod_wsgi and instead just use the inbuilt development server provided by the Python web framework you use. That will save you a lot of headaches initially if you know nothing about Apache.
正如丹尼尔建议的那样,我建议您使用 Flask。你也可以使用 web2py,这是另一个对新手来说很容易的框架。我还建议,如果您刚刚开始学习这些东西,请不要使用 Apache/mod_wsgi,而是使用您使用的 Python Web 框架提供的内置开发服务器。如果您对 Apache 一无所知,那么最初这将为您省去很多麻烦。
回答by Daniel Roseman
mod_wsgi doesn't run Python scripts like that. It's a method of hosting long-running Python applications in separate processes, which are dispatched to by Apache. And anyway, you don't just install Apache modules by "pasting" them into a folder.
mod_wsgi 不会像那样运行 Python 脚本。这是一种在单独的进程中托管长时间运行的 Python 应用程序的方法,这些进程由 Apache 分派。无论如何,您不仅仅是通过将 Apache 模块“粘贴”到文件夹中来安装它们。
If you just want to run Python scripts by giving their path to Apache, which by the way is a pretty horrible way to do it, you just want to configure Apache so that it treats Python scripts as CGI. There's plenty of documentation on how to do this.
如果您只想通过将路径提供给 Apache 来运行 Python 脚本,顺便说一下,这是一种非常糟糕的方式,您只想配置 Apache,使其将 Python 脚本视为 CGI。有很多关于如何做到这一点的文档。
But a much better way is to serve your code is by writing a proper WSGI service, probably by using one of the many minimal frameworks around - my favourite is Flask.
但是更好的方法是编写一个合适的 WSGI 服务来为你的代码提供服务,可能是使用周围的许多最小框架之一 - 我最喜欢的是Flask。