如何使用 Wampserver 安装 Python [英] How to install Python with Wampserver

查看:57
本文介绍了如何使用 Wampserver 安装 Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Windows 上安装带有 Wamp 或 Appserv 的 Python,如何安装?可以一起运行吗?

I want install Python with Wamp or Appserv on windows, how to install ? can it run together ?

推荐答案

Python 支持可以很容易地添加到 WampServer,类似于添加任何未随基本包提供的 Apache 模块.您需要采取一些额外的步骤来确保您可以继续使用 WampServer 控制台来管理您的应用程序堆栈.

Python support can be added to WampServer fairly easily, similar to adding any Apache module that doesn't ship with the base package. You need to take a few extra steps to make sure you can continue to use WampServer console to manage your application stack.

您需要获得适当的二进制版本的 mod_wsgi.WSGI 是用 Python 编写 Web 应用程序的首选方法.您使用的二进制文件必须与您使用的 Windows、Apache 和 Python 的版本相匹配.此站点提供当前版本的二进制文件:mod_wsgi 二进制文件.注意:如果您完全担心安全性,您可能应该从源代码编译您自己的 mod_wsgi 版本,或者仅从受信任的来源下载.

You'll need to get an appropriate binary version of mod_wsgi. WSGI is the preferred method for writing web applications in Python. The binary you use has to match up with the versions of Windows, Apache, and Python you are using. This site provides binaries for current versions: mod_wsgi binaries. NOTE: If you are at all concerned about security, you should probably compile your own version of mod_wsgi from the source code, or only download from a trusted source.

二进制文件进入 Apache 模块目录.就我而言,我下载了 mod_wsgi-3.4.ap22.win-amd64-py2.7.zip(Windows 7 64 位、Python 2.7、Apache 2.2).在我的笔记本电脑上,正确的目录是 c:\wamp\bin\apache\Apache2.4.4\modules.

The binary goes into the Apache modules directory. In my case, I downloaded mod_wsgi-3.4.ap22.win-amd64-py2.7.zip (Windows 7 64-bit, Python 2.7, Apache 2.2). On my laptop, the correct directory was c:\wamp\bin\apache\Apache2.4.4\modules.

接下来,您需要更新 httpd.conf.这可以通过从菜单中选择 Apache->httpd.conf 从 WampServer 控制面板完成.记事本(或您的默认编辑器)将启动.

Next, you need to update httpd.conf. This can be done from the WampServer control panel by Selecting Apache->httpd.conf from the menu. Notepad (or your default editor) will launch.

找到有一堆 LoadModule 语句的部分.在本节底部,为 mod_wsgi 添加 LoadModule 语句:

Find the section where there is a bunch of LoadModule statements. At the bottom of this section, add a LoadModule statement for mod_wsgi:

LoadModule wsgi_module modules/mod_wsgi.so

保存 httpd.conf 文件并退出记事本.

Save the httpd.conf file and exit Notepad.

要让 WampServer 知道您进行了更改,您需要对其进行刷新.右键单击系统托盘中的 WampServer 图标,然后选择刷新.现在,当您查看控制面板(Apache->Apache 模块)中的模块列表时,您应该会在列表中看到 mod_wsgi.如果尚未检查,请继续检查.如果 Apache 没有自动重新启动,请立即从控制面板重新启动.

To let WampServer know that you've made a change, you'll need to refresh it. Right-click the WampServer icon in the system tray, and select Refresh. Now, when you look at the list of modules in the control panel (Apache->Apache Modules) you should see mod_wsgi in the list. If it isn't already checked, go ahead and check it. If Apache doesn't restart automatically, do so now from the control panel.

如果 Apache 没有启动,并且您确定没有错误输入上面的 LoadModule 语句,那么很可能您的 WampServer 安装的版本与您下载的 mod_wsgi 二进制文件之间存在版本不匹配.

If Apache doesn't start up, and you are sure you didn't mistype the LoadModule statement above, then most likely you have a version mis-match between what your WampServer has installed, and the mod_wsgi binary you downloaded.

此步骤将根据您使用的应用程序框架(cherrypy、Django 等)而有所不同.我将提供一个非常基本的示例,以确保一切正常;此示例严格遵循官方 WSGI 文档.

This step will vary depending on what application framework you are using (cherrypy, Django, etc). I'll provide a really basic example to make sure everything is working correctly; this example closely follows the official WSGI documentation.

创建一个目录来保存您的 WSGI 应用程序.我创建了一个名为 C:\code\wsgi 的目录.在那里,创建一个 Python 模块来实现一个名为应用程序"的函数.每当您的应用程序 URL 被调用时,这将是您的应用程序的入口点.

Create a directory to hold your WSGI application. I created a directory called C:\code\wsgi. In there, create a Python module that implements a function called 'application'. This will be the entry point for your application whenever your application URL is called.

我调用了我的模块 wsgi.py:

I called my module wsgi.py:

def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]

    start_response(status, response_headers)

    return [output]

接下来,您需要更新 Apache httpd.conf 文件以将 WSGI 指向您的应用程序.在我的用例中,我正在维护一个 PHP 站点,同时使用 Python 对新站点进行一些原型设计.为了将两者分开,我在 Apache 中定义了一个虚拟服务器,监听不同的端口号.我还添加了 IfModule 指令,因此如果我使用 WampServer 控制面板禁用 mod_wsgi,那么这些语句将被忽略.

Next, you'll need to update your Apache httpd.conf file to point WSGI at your application. In my use case, I was maintaining a PHP site while doing some prototyping of a new site using Python. To keep the two separate, I defined a virtual server in Apache, listening on a different port number. I also added the IfModule directive, so that if I disable mod_wsgi using the WampServer control panel, then these statements are ignored.

<IfModule wsgi_module>
    <VirtualHost *:8090>
        WSGIScriptAlias /myapp /code/wsgi/wsgi.py
        <Directory /code/wsgi>
            Order allow,deny
            Allow from all
        </Directory>
    </VirtualHost>
</IfModule>

测试一下

使用 WampServer 控制面板重新启动 Apache.如果一切顺利,您应该可以输入

Test It

Restart Apache using the WampServer control panel. If all is well, you should be able to type

http://localhost:8090/myapp 

进入您的浏览器,并看到 Hello, World!显示的消息.

into your browser, and see the Hello, World! message displayed.

用于 mod_wsgi 的较新版本的 Windows 二进制文件使用 whl 文件格式打包.whl 文件是一个 Python PIP轮"文件.它与 ZIP 兼容,因此您可以使用 .zip 扩展名重命名文件以提取 mod_wsgi.so 文件(从数据目录).

Newer releases of the Windows binaries for mod_wsgi are packaged using the whl file format. The whl file is a Python PIP "wheel" file. It's compatible with ZIP, so you can rename the file using a .zip extension to extract the mod_wsgi.so file (from the data directory).

或者,您可以运行 'pip install (packagename).whl' 将 mod_wsgi.so 作为 Python 包安装.您必须找出 Python 提取 mod_wsgi.so 文件的位置并将其复制到正确的位置(如有必要).

Alternately, you can run 'pip install (packagename).whl' to install mod_wsgi.so as a Python package. You would have to find out where Python extracted the mod_wsgi.so file and copy it to the right place (if necessary).

我对最新版本的 WAMP 服务器使用了前一种方法.正确的文件是 mod_wsgi-4.4.11+ap24vc10-cp34-none-win32.whl.名称的cpNN"部分应与您安装的 Python 版本相匹配.

I used the former approach for the latest version of WAMP Server. The correct file was mod_wsgi-4.4.11+ap24vc10-cp34-none-win32.whl. The 'cpNN' part of the name should match up with the version of Python you have installed.

这篇关于如何使用 Wampserver 安装 Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆