wsgi + apache中的ModuleNotFoundError,尽管已安装并配置了python路径

问题描述 投票:1回答:1

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

[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列表看起来像这样(从django.core.wsgi运行,在python控制台上可以正常运行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,non-virtualenvs,一切。

python django apache ubuntu wsgi
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.