【问题标题】:ModuleNotFoundError in wsgi + apache despite installed and python path configured尽管已安装并配置了 python 路径,但 wsgi + apache 中的 ModuleNotFoundError
【发布时间】:2020-05-10 09:05:36
【问题描述】:

所以我将所有要求安装到虚拟环境中,但是仍然显示此错误

[Fri Jan 24 10:14:11.568489 2020] [wsgi:error] [pid 7677:tid 139735752533760] [remote 168.70.107.79:35002] mod_wsgi (pid=7677): Target WSGI script '/root/pw_x_web/PW_X_Web/wsgi.py' cannot be loaded as Python module.

[Fri Jan 24 10:14:11.568566 2020] [wsgi:error] [pid 7677:tid 139735752533760] [remote 168.70.107.79:35002] mod_wsgi (pid=7677): Exception occurred processing WSGI script '/root/pw_x_web/PW_X_Web/wsgi.py'.

[Fri Jan 24 10:14:11.568773 2020] [wsgi:error] [pid 7677:tid 139735752533760] [remote 168.70.107.79:35002] Traceback (most recent call last):

[Fri Jan 24 10:14:11.568797 2020] [wsgi:error] [pid 7677:tid 139735752533760] [remote 168.70.107.79:35002]   File "/root/pw_x_web/PW_X_Web/wsgi.py", line 12, in <module>

[Fri Jan 24 10:14:11.568801 2020] [wsgi:error] [pid 7677:tid 139735752533760] [remote 168.70.107.79:35002]     from django.core.wsgi import get_wsgi_application

[Fri Jan 24 10:14:11.568819 2020] [wsgi:error] [pid 7677:tid 139735752533760] [remote 168.70.107.79:35002] ModuleNotFoundError: No module named 'django'

我的 pip3 列表看起来像这样(在 python 控制台上运行 from django.core.wsgi import get_wsgi_application 很好)

amqp (2.5.2)
argh (0.26.2)
asgiref (3.2.3)
bcrypt (3.1.7)
billiard (3.6.1.0)
celery (4.4.0)
certifi (2019.11.28)
cffi (1.13.2)
chardet (3.0.4)
Django (3.0.2)
django-dbbackup (3.2.0, /root/pw_x_web/venv/src/django-dbbackup)
django-livesync (0.5)
django-recaptcha2 (1.4.1)
docopt (0.6.2)
idna (2.8)
importlib-metadata (1.4.0)
kombu (4.6.7)
more-itertools (8.1.0)
mysqlclient (1.4.6)
pathtools (0.1.2)
Pillow (7.0.0)
pip (9.0.1)
pkg-resources (0.0.0)
pycparser (2.19)
python-dateutil (2.8.1)
pythonanywhere (0.8.3)
pytz (2019.3)
PyYAML (5.3)
requests (2.22.0)
schedule (0.6.0)
setuptools (39.0.1)
six (1.14.0)
sqlparse (0.3.0)
tornado (6.0.3)
urllib3 (1.25.7)
vine (1.3.0)
watchdog (0.9.0)
websocket-client (0.57.0)
zipp (2.0.0)

我的 apache 配置文件看起来像这样

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        Alias /static /root/pw_x_web/static
        <Directory /root/pw_x_web/static>
                Require all granted
        </Directory>
Alias /media /root/pw_x_web/media
        <Directory /root/pw_x_web/media>
                Require all granted
        </Directory>

        <Directory /root/pw_x_web/PW_X_Web>
                <Files wsgi.py>
                        Require all granted
                </Files>
        </Directory>

        <Directory />
               Require all granted
        </Directory>
        WSGIScriptAlias / /root/pw_x_web/PW_X_Web/wsgi.py
        WSGIDaemonProcess django_app python-path=/root/pw_x_web/venv
        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
        WSGIProcessGroup django_app

</VirtualHost>

我已经研究了几个小时来解决这个问题,但我找不到一个可行的方法。我尝试了virutalenvs,非virtualenvs,一切。

【问题讨论】:

    标签: python django apache ubuntu wsgi


    【解决方案1】:

    我昨天也遇到了同样的问题。我通过完全删除 virtualenv 然后重新创建它并在执行 pip3 install -r requirements.txt 之前安装了 django 来解决它,它确实有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-03
      • 2019-11-06
      • 2020-04-27
      • 2020-07-06
      • 2011-09-04
      • 1970-01-01
      • 2018-01-23
      相关资源
      最近更新 更多