wsgi.py 无法加载为 Python 模块错误/没有名为 'django.core' 的模块



我已经在Centos 7上用Apache 2.4.6-93.、mod_wsgi、Virtualenv和Postgres配置了Django 2.1.15。

这是我的apache conf文件:

<VirtualHost *:80>
DocumentRoot /var/www/
Alias /static /var/www/myapp/static
<Directory /var/www/myapp/static>
Options FollowSymLinks
Order allow,deny
Allow from all
Require all granted
</Directory>

ErrorLog /var/www/myapp/logs/apis_error.log
CustomLog /var/www/myapp/logs/apis_access.log combined
LogLevel info
WSGIPassAuthorization On
WSGIDaemonProcess myapp  python-path=/var/www/myapp:/var/www/myapp/venv/lib/python3.6/site-packages
WSGIProcessGroup myapp
WSGIApplicationGroup %{GLOBAL}
WSGIScriptAlias / /var/www/myapp/myapp/wsgi.py
<Directory /var/www/myapp/myapp/myapp>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>

Apache日志错误:

[wsgi:error] [pid 4829]  mod_wsgi (pid=4829, process='myapp', application=''): Loading WSGI script '/var/www/myapp/myapp/wsgi.py'.
[wsgi:error] [pid 4829]  mod_wsgi (pid=4829): Target WSGI script '/var/www/myapp/myapp/wsgi.py' cannot be loaded as Python module.
[wsgi:error] [pid 4829]  mod_wsgi (pid=4829): Exception occurred processing WSGI script '/var/www/myapp/myapp/wsgi.py'.
[wsgi:error] [pid 4829]  Traceback (most recent call last):
[wsgi:error] [pid 4829]    File "/var/www/myapp/myapp/wsgi.py", line 12, in <module>
[wsgi:error] [pid 4829]      from django.core.wsgi import get_wsgi_application
[wsgi:error] [pid 4829]  ModuleNotFoundError: No module named 'django.core'
[wsgi:info]  [pid 4829] mod_wsgi (pid=4829, process='myapp', application=''): Loading WSGI script '/var/www/myapp/myapp/wsgi.py'.
[wsgi:error] [pid 4829] mod_wsgi (pid=4829): Target WSGI script '/var/www/myapp/myapp/wsgi.py' cannot be loaded as Python module.
[wsgi:error] [pid 4829]  mod_wsgi (pid=4829): Exception occurred processing WSGI script '/var/www/myapp/myapp/wsgi.py'.
[wsgi:error] [pid 4829]  Traceback (most recent call last):
[wsgi:error] [pid 4829]    File "/var/www/myapp/myapp/wsgi.py", line 12, in <module>
[wsgi:error] [pid 4829]      from django.core.wsgi import get_wsgi_application
[wsgi:error] [pid 4829]  ModuleNotFoundError: No module named 'django.core'

知道这里可能发生了什么吗?

谢谢!

我认为您需要像一样对vhostconf进行一些更改

<VirtualHost *:80>
ServerName myapp.local  # HERE: "ServerName" is missing
DocumentRoot /var/www/myapp  # HERE: point to the root folder of your app

Alias /static /var/www/myapp/static
<Directory /var/www/myapp/static>
# Options FollowSymLinks
# Order allow,deny
# Allow from all
Require all granted
</Directory>
WSGIPassAuthorization On
WSGIDaemonProcess myapp  python-path=/var/www/myapp:/var/www/myapp/venv/lib/python3.6/site-packages
WSGIProcessGroup myapp
WSGIApplicationGroup %{GLOBAL}

WSGIScriptAlias / /var/www/myapp/myapp/wsgi.py
<Directory /var/www/myapp/myapp>  # HERE: give the right location of "wsgi.py"
<Files wsgi.py>
Require all granted
</Files>
</Directory>
LogLevel info
ErrorLog /var/www/myapp/logs/apis_error.log
CustomLog /var/www/myapp/logs/apis_access.log combined
</VirtualHost>

如果这对你有用,请告诉我。

最新更新