从与Apache / mod_wsgi的一个运行的virtualenv的Python,在Windows [英] Running Python from a virtualenv with Apache/mod_wsgi, on Windows

查看:620
本文介绍了从与Apache / mod_wsgi的一个运行的virtualenv的Python,在Windows的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立WAMP服务器。我有Apache的正常工作,我已经安装mod_wsgi的顺利进行。

I'm trying to set up WAMP server. I've got Apache working correctly, and I've installed mod_wsgi without a hitch.

问题是,我使用的是虚拟环境(使用的virtualenv)为我的项目。所以很明显,mod_wsgi的是具有定位我安装的Django的问题。

Problem is, I'm using virtual environments (using virtualenv) for my projects. So obviously, mod_wsgi is having problems locating my installation of Django.

我想知道我怎么能得到的mod_wsgi与virtualenvs很好地工作。文档似乎认为这是不可能的:

I'm trying to understand how I can get mod_wsgi to work well with the virtualenvs. The documentation seems to think this isn't possible:

请注意,该WSGIPythonHome指令只能在UNIX系统上使用,不适用于Windows系统。这是因为在Windows系统上的Python DLL的位置似乎是什么决定了在那里的Python会寻找Python库文件。它不是在这一点上已知的怎么会在Windows创建一个独特的环境基线独立于主Python安装的。

Note that the WSGIPythonHome directive can only be used on UNIX systems and is not available on Windows systems. This is because on Windows systems the location of the Python DLL seems to be what dictates where Python will look for the Python library files. It is not known at this point how one could create a distinct baseline environment independent of the main Python installation on Windows.

从这里开始:的mod_wsgi +的virtualenv文档

有没有人对如何使这项工作?一些想法

Does anyone have some idea on how to make this work?

推荐答案

您可以通过编程在Python启动环境导入任何事情之前添加以下内容到.wsgi文件。

You can activate the environment programmatically from Python adding this to your .wsgi file before importing anything else.

的virtualenv的文档:

有时你不能或不想
  使用由创建了Python间preTER
  在virtualenv中。例如,在一
  mod_python的或mod_wsgi的环境,
  只有一个间preTER

Sometimes you can't or don't want to use the Python interpreter created by the virtualenv. For instance, in a mod_python or mod_wsgi environment, there is only one interpreter.

幸运的是,这很容易。您必须使用
  定制的Python间preTER安装
  库。但使用库,你
  只是要确定路径
  正确。脚本是可用
  纠正的路径。您可以设置
  环境,如:

Luckily, it's easy. You must use the custom Python interpreter to install libraries. But to use libraries, you just have to be sure the path is correct. A script is available to correct the path. You can setup the environment like:

activate_this = '/path/to/env/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))

这将改变sys.path中,甚至
  改变SYS。preFIX,也让你
  使用现有的跨preTER。项目
  在您的环境将显示第一
  在sys.path中,全球性项目前。
  但是,这不能撤消
  其他环境中的活化,或
  已导入模块。您
  不应该试图,例如
  网络之前激活的环境
  请求;你应该激活一个
  环境尽早,和
  不是在这个过程中做一遍。

This will change sys.path and even change sys.prefix, but also allow you to use an existing interpreter. Items in your environment will show up first on sys.path, before global items. However, this cannot undo the activation of other environments, or modules that have been imported. You shouldn't try to, for instance, activate an environment before a web request; you should activate one environment as early as possible, and not do it again in that process.

这篇关于从与Apache / mod_wsgi的一个运行的virtualenv的Python,在Windows的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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