我在运行django和apache2 / mod_wsgi时遇到问题。这是我目前的设置:
Ubuntu: 16.0
Apache: 2.4.18
Python: 3.5
Django: 1.10
我已经在我的django项目中为用户' carma'安装了virtualenv。结构是:
/home/carma/mycarma
|- manage.py
static
mycarma
|__init__.py
|settings.py
|urls.py
|wsgi.py
mycarmanev
bin
include
lib
这是 /etc/apache2/sites-available/000-default.conf
的内容<VirtualHost *:80>
Alias /static /home/carma/mycarma/static
<Directory /home/carma/mycarma/static>
Require all granted
</Directory>
<Directory /home/carma/mycarma/mycarma>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess mycarma python-path=/home/carma/mycarma/ python-home=/home/carma/mycarma/mycarmavirtuale$
WSGIProcessGroup mycarma
WSGIScriptAlias / /home/carma/mycarma/mycarma/wsgi.py
这是 wsgi.py
的内容import os,sys
from django.core.wsgi import get_wsgi_application
DJANGO_PATH = os.path.join(os.path.abspath(os.path.dirname(__file__)), '..')
sys.path.append(DJANGO_PATH)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mycarma.settings")
application = get_wsgi_application()
我已经授予了权限:
sudo chown -R www-data:www-data /home/carma/mycarma/mycarmaenv
sudo chown -R www-data:www-data /home/carma/mycarma
当我尝试访问服务器的url,检查apache日志时出现问题:
[wsgi:error] [pid 25183] mod_wsgi (pid=25183): Target WSGI script '/home/carma/mycarma/mycarma/wsgi.py' cannot be loaded as Python module.
[wsgi:error] [pid 25183] mod_wsgi (pid=25183): Exception occurred processing WSGI script '/home/carma/mycarma/mycarma/wsgi.py'.
[wsgi:error] [pid 25183] Traceback (most recent call last):
[wsgi:error] [pid 25183] File "/home/carma/mycarma/mycarma/wsgi.py", line 12, in <module>
[wsgi:error] [pid 25183] from django.core.wsgi import get_wsgi_application
[wsgi:error] [pid 25183] ImportError: No module named 'django'
我已经阅读了此处和外部的所有可能的讨论,也发现了this thread,它们暴露了完全相同的问题,但没有任何对我有用。
感谢任何帮助!
答案 0 :(得分:3)
我认为这是一个错字,mycarmanev
或mycarmavirtuanev
?
WSGIDaemonProcess mycarma python-path=/home/carma/mycarma/ python-home=/home/carma/mycarma/myprojectenv