ImportError:Ubuntu中没有名为apache的模块,名为django.core.wsgi。

时间:2018-07-24 12:57:58

标签: python django apache ubuntu

首先,我必须告诉您,我已经看到许多解决此问题的方法。我已经尝试了大多数。但是仍然无法解决问题。所以我再次发布。 请找到我的000-default.conf用于apache

WSGIPythonHome /usr
WSGIPythonPath /home/test-admin/Documents/web_project:/home/test-admin/.local/lib/python2.7/site-packages

<VirtualHost *:80>

Alias /static /home/test-admin/Documents/web_project/static
<Directory /home/test-admin/Documents/web_project/static>
    Require all granted
</Directory>

<Directory /home/test-admin/Documents/web_project/website>
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>

WSGIDaemonProcess test-collection 
WSGIProcessGroup test-collection
WSGIScriptAlias / /home/test-admin/Documents/web_project/website/wsgi.py
ServerName www.test-collection.com
ServerAlias test-collection.com
ServerAdmin admin@test-collection.com

sys.prefix

>>> import sys
>>> sys.prefix
'/usr'
>>> 

wsgi.py

import os
import sys

path = r'/home/test-admin/.local/lib/python2.7/site-packages'
if path not in sys.path:
    sys.path.append(path)

path = r'/home/test-admin/Documents/web_project'
if path not in sys.path:
    sys.path.append(path)

sys.stderr.write('\n'.join(sys.path))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "website.settings")
from django.core.wsgi import get_wsgi_application

application = get_wsgi_application()

然后在路径中安装了django

  

r'/ home / test-admin / .local / lib / python2.7 / site-packages'

并输出ldd /usr/lib/apache2/modules/mod_wsgi.so

linux-vdso.so.1 (0x00007ffccd7d1000)
    libpython2.7.so.1.0 => /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 (0x00007f0eeb607000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f0eeb3e8000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f0eeaff7000)
    libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f0eeadda000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f0eeabd6000)
    libutil.so.1 => /lib/x86_64-linux-gnu/libutil.so.1 (0x00007f0eea9d3000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f0eea635000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f0eebdbe000)

所以我认为mod_wsgi是为python 2.7安装的。并尝试在错误日志中打印sys.path,我猜它来的正确。请在下面找到error.log。

 [wsgi:error] [pid 4021:tid 140595830531840] /usr/lib/python2.7
 [wsgi:error] [pid 4021:tid 140595830531840] /usr/lib/python2.7/plat-x86_64-linux-gnu
 [wsgi:error] [pid 4021:tid 140595830531840] /usr/lib/python2.7/lib-tk
 [wsgi:error] [pid 4021:tid 140595830531840] /usr/lib/python2.7/lib-old
 [wsgi:error] [pid 4021:tid 140595830531840] /usr/lib/python2.7/lib-dynload
 [wsgi:error] [pid 4021:tid 140595830531840] /usr/local/lib/python2.7/dist-packages
 [wsgi:error] [pid 4021:tid 140595830531840] /usr/lib/python2.7/dist-packages
 [wsgi:error] [pid 4021:tid 140595830531840] /home/test-admin/.local/lib/python2.7/site-packages
 [wsgi:error] [pid 4021:tid 140595830531840] [remote 192.168.2.115:44840] mod_wsgi (pid=4021): Failed to exec Python script file '/home/test-admin/Documents/web_project/website/wsgi.py'.
 [wsgi:error] [pid 4021:tid 140595830531840] [remote 192.168.2.115:44840] mod_wsgi (pid=4021): Exception occurred processing WSGI script '/home/test-admin/Documents/web_project/website/wsgi.py'.
 [wsgi:error] [pid 4021:tid 140595830531840] [remote 192.168.2.115:44840] Traceback (most recent call last):
 [wsgi:error] [pid 4021:tid 140595830531840] [remote 192.168.2.115:44840]   File "/home/test-admin/Documents/web_project/website/wsgi.py", line 23, in <module>
 [wsgi:error] [pid 4021:tid 140595830531840] [remote 192.168.2.115:44840]     from django.core.wsgi import get_wsgi_application
 [wsgi:error] [pid 4021:tid 140595830531840] [remote 192.168.2.115:44840] ImportError: No module named django.core.wsgi

我没有使用任何虚拟环境。请在下面找到版本信息

  1. Django 1.11.13
  2. Python 2.7.15
  3. Apache 2.4.29
  4. Ubuntu 18.04

能帮我解决这个问题吗?我花了将近一天的时间来解决这个问题。先感谢您。如果我在这里丢失任何信息,请告诉我。

0 个答案:

没有答案