python虚拟环境搭建安装flask框架,在仅使用虚拟环境安装的Python版本的Apache上部署Python Flask App...

I am working on a CentOS7 development environment. The machine came with Python 2.7.5 pre-installed. I have developed a web application using Python 3.5.1 which along with it's dependencies was installed in the virtual environment only. Python 3 is not installed machine-wide. I am now trying to deploy the application on an Apache server but have run into trouble. Here is what I have done.

I installed mod_wsgi using yum.

I configured the virtualhost as shown below:

ServerName myapp.myserver.com

WSGIDaemonProcess myapp user=myuser group=mygroup threads=5 python-path=/var/www/myapp.myserver.com/html:/var/www/myapp.myserver.com/venv/lib:/var/www/myapp.myserver.com/venv/lib/python3.5/site-packages python-home=/var/www/myapp.myserver.com/html/venv

WSGIScriptAlias / /var/www/myapp.myserver.com/html/myapp.wsgi

WSGIProcessGroup smex

WSGIApplicationGroup %{GLOBAL}

Order deny,allow

Allow from all

My wsgi file is configured as shown below:

import sys

sys.path.insert(0, '/var/www/myapp.myserver.com/html')

activate_this = '/var/www/myapp.myserver.com/html/venv/bin/activate_this.py'

with open(activate_this) as file_:

exec(file_.read(), dict(__file__=activate_this))

from myapp import app as application

However, I am getting an internal server error when I try to open the site. The error log reveals the following:

Tue Oct 18 14:24:50.174740 2016] [mpm_prefork:notice] [pid 27810] AH00163: Apache/2.4.6 (CentOS) PHP/5.4.16 mod_wsgi/3.4 Python/2.7.5 configured -- resuming normal operations

[Tue Oct 18 14:24:50.174784 2016] [core:notice] [pid 27810] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'

ImportError: No module named site

ImportError: No module named site

ImportError: No module named site

ImportError: No module named site

The last error keeps repeating for most of the log file. The first thing that catches my eye is the Python version which seems to be 2.7.5. This brings me to my questions:

Do I need to have Python 3.5.1 installed in /usr/local or can I just have it in the virtual environment.

Do I need to install a specific mod_wsgi version for this version of Python? If so should I install it via pip instead of yum?

What else am I missing to get this to work?

Thanks in advance for your help.

解决方案

Check out the Software Collections Library (SCL) at https://www.softwarecollections.org for CentOS/RHEL, don't use any default system Python, Apache or mod_wsgi packages. The SCL provides newer versions of Python and Apache than the default system versions. Then build mod_wsgi from source code against the SCL versions of Python and Apache. You cannot force mod_wsgi to use a Python virtual environment for a different version of Python than what mod_wsgi was compiled for.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值