如何在 Wampserver 上设置和运行 Python?

发布于 2024-08-19 04:20:48 字数 281 浏览 5 评论 0原文

谁能帮我设置 Python 在 Wampserver 上运行。根据我到目前为止所读到的内容,您需要结合使用 Wampser、Python、mod_pyhton 以及对 Apache http.conf 文件的调整。我已经尝试过,但我相信在版本方面我遇到了冲突。有谁知道可以工作的版本组合,以便我可以使用我的 wampserver 进行一些本地 python 开发?下载链接将不胜感激。

我当前的配置: Wampserver 2.0c => Apache版本:2.2.8,PHP版本:5.2.6,MySQL版本:5.0.51b

Can anyone help me to set up Python to run on Wampserver. From what I've read so far you would need to use a combination of Wampser, Python, mod_pyhton, and adjustment to the Apache http.conf file. I've tried it but i belive i am having conflict when it comes to versions. Does anyone know of a cobination of versions that can work so that i can do some local python development using my wampserver? Links to the download would be greatly appreciated.

My current config:
Wampserver 2.0c =>
Apache Version : 2.2.8 , PHP Version : 5.2.6 , MySQL Version : 5.0.51b

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

维持三分热 2024-08-26 04:20:48

不要使用mod_python;它并没有像大多数人认为的那样做。请改用 mod_wsgi

Do not use mod_python; it does not do what most people think it does. Use mod_wsgi instead.

莫相离 2024-08-26 04:20:48

如何使用 web.py (下载)还是django

他们有自己的Web服务器,您还可以使用MySQLdb扩展连接MySQL服务器。

How about using web.py (download) or django?

They have their own web server, and you can also connect MySQL server with MySQLdb extension.

你爱我像她 2024-08-26 04:20:48

认识到该帖子询问了 mod_python,我发布以下内容,以防使用 CGI 可以接受。

我已经有一段时间没有让它工作了,但我得到了用 Python 编写的 CGI 脚本,可以在 Wampserver 下运行,只需做一些简单的事情(尽管当时看起来并不简单):

  • 如果你还没有,请下载并安装 Python已经。标准安装应该允许您从命令提示符运行程序(您将需要它)。
  • 编写 Python CGI 程序,使第一行成为 #!python (或 python 可执行文件的完整路径)。虽然 Windows 下的 Python 程序通常不需要第一行,但 Apache 似乎需要这一行,以便它知道该程序是 Python。
  • 将程序放置在 cgi-bin 目录中。

应该可以做到这一点。我仔细检查了 httpd.conf 文件,没有看到任何使 Python 工作的更改。 (这假设您已经让 CGI 正常工作。)

下面的简单脚本应该告诉您是否可以正常工作:

#!python
print "Content-type: text/html"
print ""
print "<html>"
print "<head>"
print "<title>CGI Test of Python</title>"
print "</head>"
print "<body>"
print "This is a test"
print "</body>"
print "</html>"

Recognising that the post asks about mod_python, I'm posting the following, in case using CGI is acceptable.

It has been a while since I got this to work, but I got CGI scripts written with Python to run under Wampserver with a couple simple things (although it didn't seem simple at the time):

  • Download and install Python if you haven't already. The standard install should let you run programs from a command prompt (which you'll need).
  • Write your Python CGI program, making the first line be #!python (or the full path to the python executable). While the first line isn't usually necessary for Python programs under Windows, Apache seems to need this so it knows the program is Python.
  • Place the program in your cgi-bin directory.

That should do it. I double checked my httpd.conf file and don't see any changes to get Python working. (This assumes you already have CGI working otherwise.)

The following simple script should tell you if you have things working:

#!python
print "Content-type: text/html"
print ""
print "<html>"
print "<head>"
print "<title>CGI Test of Python</title>"
print "</head>"
print "<body>"
print "This is a test"
print "</body>"
print "</html>"
樱娆 2024-08-26 04:20:48

我的 WSGI 设置是在 WAMP 服务器 2.5、32 位上进行的(Apache 2.4.9 32位)
Win32 上的 PythonWin 2.7.8(默认,2014 年 7 月 2 日,19:50:44)[MSC v.1500 32 位(Intel)] 继续下一步。

WAMP route = C:/wamp/

配置 Apache

http://www.apachelounge.com/viewtopic.php 下载 32 位 mod_wsgi.so ?t=5143 并将其放置为
c:\wamp\bin\apache\apache2.4.9\modules\mod_wsgi.so

在主C:\wamp\bin\apache\apache2.4.9\conf\httpd.conf中加载wsgi模块到apache:

LoadModule wsgi_module modules/mod_wsgi.so 
WSGIScriptAlias /API c:/wamp/www/API/code.py 

获取webpy

C:\tmp>git clone git://github.com/webpy/webpy.git
C:\tmp>python webpy\setup.py install

测试一下:

C:\tmp>python
ActivePython 2.7.8.10 (ActiveState Software Inc.) based on 
Python 2.7.8(default, Jul  2 2014, 19:50:44) [MSC v.1500 32 bit (Intel)] 
on win32  Type "help", "copyright", "credits" or "license" for more information.
>>> import web
>>>

将应用程序创建为 c:\wamp\www\API\code.py

import web
urls = (
  '', 'root',
  '/(.*)', 'hello',
  )

class root:
    def GET(self):
        return "This is the root URI."

class hello:
    def GET(self, name):
        return "Hello %s from webPy." % name

application = web.application(urls, globals()).wsgifunc()

结果

重新启动 apache Web 服务器并检查 http://localhost/API

My WSGI setup made on WAMP server 2.5, 32bits (Apache 2.4.9 32bits) with
PythonWin 2.7.8 (default, Jul 2 2014, 19:50:44) [MSC v.1500 32 bit (Intel)] on win32 went on the next way.

WAMP route = C:/wamp/

Config Apache

Download 32bits mod_wsgi.so from http://www.apachelounge.com/viewtopic.php?t=5143 and place it as
c:\wamp\bin\apache\apache2.4.9\modules\mod_wsgi.so

Load the wsgi module to apache in the main C:\wamp\bin\apache\apache2.4.9\conf\httpd.conf:

LoadModule wsgi_module modules/mod_wsgi.so 
WSGIScriptAlias /API c:/wamp/www/API/code.py 

Get webpy

C:\tmp>git clone git://github.com/webpy/webpy.git
C:\tmp>python webpy\setup.py install

Test it:

C:\tmp>python
ActivePython 2.7.8.10 (ActiveState Software Inc.) based on 
Python 2.7.8(default, Jul  2 2014, 19:50:44) [MSC v.1500 32 bit (Intel)] 
on win32  Type "help", "copyright", "credits" or "license" for more information.
>>> import web
>>>

Create your application as c:\wamp\www\API\code.py

import web
urls = (
  '', 'root',
  '/(.*)', 'hello',
  )

class root:
    def GET(self):
        return "This is the root URI."

class hello:
    def GET(self, name):
        return "Hello %s from webPy." % name

application = web.application(urls, globals()).wsgifunc()

Result

Restart your apache webserver and check http://localhost/API

相思碎 2024-08-26 04:20:48

第 1 步:下载 Python 安装程序
https://www.python.org/downloads/release/python-350/< /a>

第 2 步:安装 Python

第 3 步:下载 wampserver
https://sourceforge.net/projects/wampserver/files/WampServer %202/Wampserver%202.4/

步骤 4:在记事本中打开 httpd.conf 文件,从该位置 C:\wamp64\bin\apache\apache2.4.23\conf\httpd.conf

步骤 5:找到 CTRL+F httpd.conf 中的“目录”,并在安装 wamp 服务器的文档目录中设置 wamp 安装位置,请使用正斜杠 < strong>"/" 不是反词 "\"

A.(DocumentRoot "C:/wamp64/www")

B.(目录 "C :/wamp64/www"> )

并替换 Directory "C:/wamp64/www"> 中的这两行;

删除:-

选项索引 FollowSymLinks

添加:-

AddHandler cgi-script .cgi .py

选项索引 FollowSymLinks ExecCGI

C. 设置 cgi-bin 位置

(目录“C:” /wamp64/cgi-bin
允许覆盖无
选项无...)

第六步:重新启动wamp的所有服务。

步骤7:制作python程序,但首先添加这些行

#!D:/paythoninstalled/python.exe//设置python的安装路径

步骤8:保存程序.py扩展。

第9步:在浏览器上运行

 localhost/file_name.py

Step 1: Download the Python Setup
https://www.python.org/downloads/release/python-350/

Step 2: Install Python

Step 3: Download the wampserver
https://sourceforge.net/projects/wampserver/files/WampServer%202/Wampserver%202.4/

Step 4: Open httpd.conf file in notepad,from that location C:\wamp64\bin\apache\apache2.4.23\conf\httpd.conf

Step 5: find CTRL+F "Directory" in httpd.conf and set wamp install location in Document and Directory , where your wamp server is installed , kindly use forward slash "/" not backword "\"

A.(DocumentRoot "C:/wamp64/www")

B.(Directory "C:/wamp64/www"> )

and Replace these two line inside Directory "C:/wamp64/www">

Remove:-

Options Indexes FollowSymLinks

Add:-

AddHandler cgi-script .cgi .py

Options Indexes FollowSymLinks ExecCGI

C. Set cgi-bin location

(Directory "C:/wamp64/cgi-bin"
AllowOverride None
Options None...)

Step 6: Restart All Service of wamp.

Step 7: make python program but add these line at first

#!D:/paython installed/python.exe // set path where python is installed

Step 8: save program .py extension.

Step 9: run on browser using

 localhost/file_name.py
葬心 2024-08-26 04:20:48

Wampserver 没有 python/django 的插件,但 XAMPP 有。

这里有一个很好的教程:

http://jyotirmaya.blogspot.com/2008 /11/xampp-python-django.html

Wampserver doesn't have addon for python/django, but XAMPP does.

A good tutorial here:

http://jyotirmaya.blogspot.com/2008/11/xampp-python-django.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文