简体   繁体   English

无法使用mod_wsgi运行python

[英]Unable to run python with mod_wsgi

I'm trying to deploy a Python app via mod_wsgi in Apache httpd, running into a strange error. 我正在尝试通过Apache httpd中的mod_wsgi部署Python应用程序,遇到一个奇怪的错误。 I'm using my firm's custom python package (2.7), besides this there is another Python intsallation, shipped with the OS (different version, 2.6 something). 我正在使用公司的自定义python软件包(2.7),除此之外,操作系统还附带了另一个Python集成(不同版本,版本2.6)。 The issue is, when I define the WSGIPythonHome and WSGIPythonPath variables in my httpd conf, I'm flooded with "ImportError: no module named site" errors in the error_log. 问题是,当我在httpd conf中定义WSGIPythonHome和WSGIPythonPath变量时,在error_log中充满了“ ImportError:没有名为站点的模块”错误。 Looking at other answers, defining those variables would be the solution for such errors. 查看其他答案,定义这些变量将是解决此类错误的方法。 If I switch user to the apache user, with being the PYTHONPATH and PYTHONHOME env variables set, when I try to start Python 2.7, I'm getting the same error. 如果我将用户切换为apache用户,并且设置了PYTHONPATH和PYTHONHOME env变量,那么当我尝试启动Python 2.7时,会遇到相同的错误。

After unsetting the variables, Python is able to start normally. 取消设置变量后,Python即可正常启动。 So I've tried removing the WSGIPythonHome and WSGIPythonPath from the httpd conf, but in that case, nothing happens, the wsgi script is not executed, as nothing is pointing Apache to my python executable. 因此,我尝试从httpd conf中删除WSGIPythonHome和WSGIPythonPath,但是在那种情况下,什么也没发生,wsgi脚本没有执行,因为没有任何东西将Apache指向我的python可执行文件。 The mod_wsgi.so has been installed with pip, and loaded from the same path as my PYTHONPATH would be for 2.7 mod_wsgi.so已与pip一起安装,并从与我的PYTHONPATH相同的路径加载2.7

It is likely that mod_wsgi Apache is using is compiled for Python 2.6. Apache使用的mod_wsgi很可能是针对python 2.6编译的。 You cannot make mod_wsgi compiled for Python 2.6, work with a Python 2.7 installation or virtual environment. 您不能使mod_wsgi为Python 2.6编译,不能与Python 2.7安装或虚拟环境一起使用。

You should verify what Python version mod_wsgi was compiled for by running ldd on the mod_wsgi.so binary. 您应该通过在mod_wsgi.so二进制文件上运行ldd来验证编译了哪个Python版本的mod_wsgi.so Don't assume it is using the pip installed version, you may still have system mod_wsgi installed. 不要以为它使用的是pip安装版本,您可能仍然安装了系统mod_wsgi。

If it is the system mod_wsgi package and it is compiled for Python 2.6, you will need to uninstall it. 如果它是系统的mod_wsgi软件包,并且是针对Python 2.6编译的,则需要将其卸载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM