我正在尝试在Ubunt16.04u服务器中设置Django-Python环境,但出现Apache错误:“ ImportError:没有名为'django'的模块” 我已经安装了Python 3.7,virtualenv(sudo pip安装virtualenv),Django(pip安装Django),mod_wsgi(sudo make install)。
可能是问题的原因?
// Apache错误日志文件
[Wed Nov 21 17:45:07.572605 2018] [wsgi:error] [pid 60818] [remote 192.168.224.1:56398] mod_wsgi (pid=60818): Target WSGI script '/var/www/django_virtualenv/progetti_django/curriculum/curriculum/wsgi.py' cannot be loaded as Python module.
[Wed Nov 21 17:45:07.572638 2018] [wsgi:error] [pid 60818] [remote 192.168.224.1:56398] mod_wsgi (pid=60818): Exception occurred processing WSGI script '/var/www/django_virtualenv/progetti_django/curriculum/curriculum/wsgi.py'.
[Wed Nov 21 17:45:07.572758 2018] [wsgi:error] [pid 60818] [remote 192.168.224.1:56398] Traceback (most recent call last):
[Wed Nov 21 17:45:07.572805 2018] [wsgi:error] [pid 60818] [remote 192.168.224.1:56398] File "/var/www/django_virtualenv/progetti_django/curriculum/curriculum/wsgi.py", line 17, in <module>
[Wed Nov 21 17:45:07.572812 2018] [wsgi:error] [pid 60818] [remote 192.168.224.1:56398] from django.core.wsgi import get_wsgi_application
[Wed Nov 21 17:45:07.572824 2018] [wsgi:error] [pid 60818] [remote 192.168.224.1:56398] ImportError: No module named 'django'
// 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.
ServerAdmin webmaster@example.com
ServerName cv-django.vmware
ServerAlias www.cv-django.vmware
DocumentRoot /var/www/django_virtualenv/progetti_django/curriculum/cv
WSGIScriptAlias / /var/www/django_virtualenv/progetti_django/curriculum/curriculum/wsgi.py
WSGIDaemonProcess cv-django.vmware processes=2 threads=15 display-name=%{GROUP} python-home=/var/www/djang$
WSGIProcessGroup cv-django.vmware
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/django_virtualenv/progetti_django/curriculum/cv/>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Alias /static/ /var/www/django_virtualenv/progetti_django/curriculum/cv/static/
<Directory /var/www/django_virtualenv/progetti_django/curriculum/cv/static>
Require all granted
</Directory>
# 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
ServerSignature On
# 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
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
// wsgi.py
import os
import time
import traceback
import signal
import sys
from django.core.wsgi import get_wsgi_application
sys.path.append('/var/www/django_virtualenv/progetti_django/curriculum/cv')
sys.path.append('/var/www/django_virtualenv/progetti_django/lib/python3.7/site-packages')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'curriculum.settings')
try:
application = get_wsgi_application()
except Exception:
# Error loading applications
if 'mod_wsgi' in sys.modules:
traceback.print_exc()
os.kill(os.getpid(), signal.SIGINT)
time.sleep(2.5)
答案 0 :(得分:0)
[已解决]错误是由于wsgi python版本不匹配所致。 Apache运行的是其他版本(Python 3.5)。
我遵循了这些帖子中的建议:
https://stackoverflow.com/posts/28118284/revisions
和