如何使用带有mod_wsgi的一个畅达的环境呢? [英] How do I use a conda environment with mod_wsgi?

查看:291
本文介绍了如何使用带有mod_wsgi的一个畅达的环境呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的第一篇文章,我是新来的Python和Apache的,所以请宽容我。我在就好了用来提供内容的使用瓶中康达环境Python的Web应用程序。现在我需要的一切服务与Apache,而不是瓶。我能得到阿帕奇与mod_wsgi的运行Python,但只能用virtualenv中。我试图与蟒蛇安装的virtualenv,但是我收到一个警告,这样的设置是不支持的,不推荐使用。所以我的问题是这样的:

My first post, and I'm new to both Python and Apache, so please go easy on me. I have a Python web application in a conda environment that serves up content just fine using Flask. Now I need to serve everything with Apache instead of Flask. I can get Apache to run Python with mod_wsgi, but only with virtualenv. I tried installing virtualenv with Anaconda, but I received a warning that such a setup is unsupported and not recommended. So my question is this:

我如何设置Apache运行我在康达环境中的应用?

How do I set up Apache to run my application in a conda environment?

这里,还有与虚拟环境中工作的一个部分,它说我需要输入行成显示在哪里可以找到我的activate_this.py WSGI文件。一个的virtualenv虚拟环境有activate_this.py,但康达环境没有。看来,如果没有激活的虚拟环境中,我只是得到错误500在我的浏览器和导入错误:没有模块名为瓶正确的指示。在我的httpd error_log中

Here, there's a section on working with virtual environments, and it says I need to enter a line into my wsgi file showing where to find activate_this.py. A virtualenv virtual environment has activate_this.py, but a conda environment does not. It seems that without the right instructions for activating the virtual environment, I'm just getting error 500 in my browser and "Import error: no module named flask" in my httpd error_log.

这是我在httpd.conf文件:

This is in my httpd.conf file:

<VirtualHost *:80>
     DocumentRoot /var/www
     WSGIScriptAlias / var/www/tsm.wsgi
     <Directory /var/www/tsm>
     Order allow,deny
     Allow from all
     </Directory>
</VirtualHost>

这是tsm.wsgi:

And here is tsm.wsgi:

import sys
import site
site.addsitedir('~/.conda/envs/tsm/lib/python2.7/site-packages')
sys.path.insert(0, '/var/www/tsm/server/time_series_machine')
sys.stdout = sys.stderr
from app import app as application

任何想法?感谢您的帮助,您可以提供。

Any ideas? Thanks for any help you can provide.

推荐答案

您的mod_wsgi将需要对蟒蛇的Python编写入手,而不是你的系统的Python。换句话说,你不能使用系统提供的mod_wsgi包,但需要自己编译。然后按照它在说:

Your mod_wsgi would need to be compiled against Anaconda Python to start with and not your system Python. In other words you cannot use the system supplied mod_wsgi packages but would need to compile it yourself. Then follow what it says in:

  • http://blog.dscpl.com.au/2014/09/using-python-virtual-environments-with.html

也就是说,使用守护进程模式,并使用蟒蛇回家选项 WSGIDaemonProcess

That is, use daemon mode and use the python-home option to WSGIDaemonProcess.

请注意,有报道称这表明蟒蛇Python,在某种程度上打破,不会与那些希望把Python系统的工作。所以可能无法工作,反正

Do note that there have been reports suggesting that Anaconda Python is broken in some way and will not work with systems that want to embed Python. So may not work anyway.

顺便说一句,你不能在路径的WSGI脚本文件反正和你正在做的方式使用'〜'。它不会扩大到成为主目录。但随后,按照职位,你就不再需要。

BTW, you cannot use '~' in the path in your WSGI script file anyway with the way you were doing it. It would not be expanded to be the home directory. But then, follow that post and you will not need that.

这篇关于如何使用带有mod_wsgi的一个畅达的环境呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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