简体   繁体   English

在Anaconda内部的Python上使用mod_wsgi配置Django时出错:“ImportError:没有名为django.core.wsgi的模块”

[英]Error while configuring Django with mod_wsgi on Python inside Anaconda: “ImportError: No module named django.core.wsgi”

I'm having few problems running django+apache2 on ubuntu. 我在ubuntu上运行django + apache2时遇到的问题很少。 Django 1.7, Apache2.4.7 Django 1.7,Apache2.4.7

I'm running anaconda stack with 3.4 as main + another environment on python 2 我在python 2上运行anaconda堆栈,主要是3.4 +另一个环境

I was trying to set up simple test site and received internal error 500, with below error messages in error log of Apache: 我试图设置简单的测试站点并收到内部错误500,以及Apache的错误日志中的以下错误消息:

[Sat Jan 10 11:56:16.095032 2015] [:error] [pid 14441:tid 140015774267136] [client 127.0.0.1:59135] ImportError: No module named django.core.wsgi
[Sat Jan 10 12:03:01.895432 2015] [:error] [pid 14439:tid 140015774267136] [client 127.0.0.1:59157] mod_wsgi (pid=14439): Target WSGI script '/PATH/mysite/wsgi.py' cannot be loaded as Python module.
[Sat Jan 10 12:03:01.895483 2015] [:error] [pid 14439:tid 140015774267136] [client 127.0.0.1:59157] mod_wsgi (pid=14439): Exception occurred processing WSGI script '/PATH/mysite/wsgi.py'.
[Sat Jan 10 12:03:01.895498 2015] [:error] [pid 14439:tid 140015774267136] [client 127.0.0.1:59157] Traceback (most recent call last):
[Sat Jan 10 12:03:01.895515 2015] [:error] [pid 14439:tid 140015774267136] [client 127.0.0.1:59157]   File "/PATH/mysite/wsgi.py", line 13, in <module>
[Sat Jan 10 12:03:01.895565 2015] [:error] [pid 14439:tid 140015774267136] [client 127.0.0.1:59157]     from django.core.wsgi import get_wsgi_application
[Sat Jan 10 12:03:01.895582 2015] [:error] [pid 14439:tid 140015774267136] [client 127.0.0.1:59157] ImportError: No module named django.core.wsgi

wsgi.py: wsgi.py:

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

its running ok with 它的运行正常

python manage.py runserver

So the issue here is (I think) mod-wsgi wasn't configured on correct python, as default python is ("mod_wsgi/3.4 Python/2.7.6 configured") and django is installed on anaconda 2.7.9 one. 所以这里的问题是(我认为)mod-wsgi没有在正确的python上配置,因为默认的python是(“mod_wsgi / 3.4 Python / 2.7.6 configured”),而django安装在anaconda 2.7.9上。

If my guess is good (please let me know what other info would we need for soultion) My question is: how do I recompile mod-wsgi so its linked against 2.7.9 environment from anaconda? 如果我的猜测是好的(请让我知道我们需要什么其他信息才能灵魂化)我的问题是:如何重新编译mod-wsgi以便它与anaconda的2.7.9环境相关联? Another question would be, can I leave it as it is and just add some directive to link to anaconda libraries? 另一个问题是,我可以保留原样并只添加一些指令链接到anaconda库吗? Which folder would be that and where do I put WSGIPythonHome directive then? 那个文件夹是什么,我在哪里放WSGIPythonHome指令呢?

Thank you for having a look 谢谢你看看

Had similar problem, answer was in virtual host file: 有类似的问题,答案是在虚拟主机文件中:

WSGIDaemonProcess mysite python-path=/path/to/mysite:/path/to/anaconda3/envs/python2/lib/python2.7/site-packages/
WSGIProcessGroup mysite
WSGIScriptAlias / /path/to/mysite/mysite/wsgi.py

ServerName www.mysite.com
ServerAlias mysite.com
ServerAdmin webmaster@mysite.com

<Directory /path/to/mysite/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>

ErrorLog /path/to/web/test/error.log

Check this setting in httpd.conf of your Apache: 检查Apache的httpd.conf的此设置:
In your <VirtualHost x:y> section, make sure that value of python-path in WSGIDaemonProcess is including the Python site-packages directory in your Anaconda installation . <VirtualHost x:y>部分中,确保WSGIDaemonProcesspython-path值包含Anaconda安装中的Python site-packages目录
Othwerwise, mod_wsgi may not find Django that you've installed for Python inside Anaconda . Othwerwise,mod_wsgi可能找不到你在Anaconda中为Python安装的Django。

For example, if you've installed Anaconda to: /opt/anaconda2 例如,如果您已将Anaconda安装到: /opt/anaconda2
Python site-packages directory may be: /opt/anaconda2/lib/python2.7/site-packages Python site-packages目录可能是: /opt/anaconda2/lib/python2.7/site-packages
Therefore, change WSGIDaemonProcess as: 因此,将WSGIDaemonProcess更改为:
WSGIDaemonProcess YOUR_PROJECT_NAME python-path=/opt/anaconda2/lib/python2.7/site-packages:YOUR_PROJECT_DIRECTORY ......
(Separate each path by colon : ) (分离由结肠每个路径:

Note: 注意:
1. The version number within the path may change according to your tools' version. 1. 路径中的版本号可能会根据您的工具版本而变化。 Please find similar path and try it. 请找到类似的路径并尝试一下。
2. This issue may happen on every Linux distribution (not only Ubuntu), even Windows. 2.每个Linux发行版(不仅仅是Ubuntu),甚至是Windows上都可能出现此问题。

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

相关问题 WSGIDaemon进程语法错误-Mod_wsgi django ImportError:没有名为django.core.wsgi的模块 - WSGIDaemon Process syntax error - Mod_wsgi django ImportError: No module named django.core.wsgi ImportError:没有名为django.core.wsgi的模块 - ImportError: No module named django.core.wsgi “ ImportError:没有名为django.core.wsgi的模块” apache错误 - “ImportError: No module named django.core.wsgi” apache error 导入错误:没有用于 wsgi 服务器设置的名为 django.core.wsgi 的模块 - ImportError: No module named django.core.wsgi for wsgi server setting Django Python mod_wsgi:ImportError:没有名为“ django”的模块 - Django Python mod_wsgi: ImportError: No module named 'django' Apache Django应用程序:ImportError:没有名为django.core.wsgi的模块 - Apache Django app: ImportError: No module named django.core.wsgi Django-ImportError:没有名为django.core.wsgi的模块 - Django - ImportError : no module named django.core.wsgi App Engine + Django:ImportError:没有名为django.core.wsgi的模块 - App Engine + Django: ImportError: No module named django.core.wsgi ImportError:使用nginx部署时,没有名为django.core.wsgi的模块 - ImportError: No module named django.core.wsgi when deploying with nginx ImportError:Elastic Beanstalk中没有名为django.core.wsgi的模块 - ImportError: No module named django.core.wsgi in Elastic Beanstalk
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM