简体   繁体   English

Django&WSGI-导入错误找不到模块django

[英]Django & WSGI - Import Error Can't find module django

I'm setting up a local dev environment in a vagrant box I've configured for django projects. 我正在为django项目配置的游民区中设置本地开发环境。 As such, virtualenv is really not too much use at this point, so I'm just installing everything in requirements.txt with the modules 因此,virtualenv在这一点上实际上并没有太多使用,所以我只是将所有模块安装在requirements.txt中

Django==1.7.3
Pillow==2.7.0
django-angular==0.7.10
djangorestframework
markdown
django-filter
mysqlclient==1.3.4

My issue is that no matter what I've tried, I consistently get 我的问题是,无论我尝试了什么,我始终如一地

Traceback (most recent call last):
File "/home/vagrant/photoapp.com/photoapp/wsgi.py", line 17, in <module>
from django.core.wsgi import get_wsgi_application
   ImportError: No module named 'django'

The application folder structure is: 应用程序文件夹结构为:

photoapp.com/
├── app
│   ├── admin.py
│   ├── __init__.py
│   ├── migrations
│   │   └── __init__.py
│   ├── models.py
│   ├── tests.py
│   └── views.py
├── manage.py
├── photoapp
│   ├── __init__.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── requirements.txt
├── templates
└── Vagrantfile

with a standard wsgi.py: 使用标准的wsgi.py:

import os
import sys

sys.path.append("/home/vagrant/photoapp.com")
sys.path.append("/home/vagrant/photoapp.com/photoapp")

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "photoapp.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

and a virtualhost file: 和一个虚拟主机文件:

<VirtualHost *:80>
    ServerName      dev.photoapp.com
    ServerAlias     photoapp.com

    DocumentRoot    "/home/vagrant/photoapp.com"

    alias /photos/  "/home/vagrant/photos/"
    alias /static/  "/home/vagrant/photoapp.com/static/"

    <Directory /home/vagrant/photoapp.com/static>
            Require all granted
    </Directory>

    <Directory /home/vagrant/photos>
            Require all granted
    </Directory>

    <Directory /home/vagrant/photoapp.com/photoapp>
            <Files wsgi.py>
                    Require all granted
            </Files>
    </Directory>

    ErrorLog        /home/vagrant/logs/error.log
    CustomLog       /home/vagrant/logs/access.log combined

    WSGIScriptAlias / /home/vagrant/photoapp.com/photoapp/wsgi.py


</VirtualHost>

But each time I access the site via dev.photoapp.com (hosts file has been modified), I get the error 500 and the traceback message above. 但是每次我通过dev.photoapp.com访问该站点(hosts文件已被修改)时,都会收到错误500和上面的回溯消息。

Note that 注意

  1. import django works from inside a python shell 从python shell内import django工程
  2. `python manage.py runserver loads up fine with url 127.0.0.1:8000 `python manage.py runserver可以使用URL 127.0.0.1:8000正常加载
  3. sys.path prints out: sys.path输出:

    ['', '/usr/bin', '/usr/local/lib/python2.7/dist-packages/django', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/IPython/extensions'] ['','/ usr / bin','/usr/local/lib/python2.7/dist-packages/django','/usr/lib/python2.7','/usr/lib/python2.7 /plat-x86_64-linux-gnu'、'/usr/lib/python2.7/lib-tk'、'/usr/lib/python2.7/lib-old'、'/usr/lib/python2.7/ lib-dynload','/ usr / local / lib / python2.7 / dist-packages','/ usr / lib / python2.7 / dist-packages','/ usr / lib / python2.7 / dist-packages / IPython的/扩展]

So I can see that the django packages are accessible on the path. 因此,我可以看到django软件包在路径上是可访问的。 But it's not resolving with Apache access. 但这不能解决Apache访问问题。

Any ideas? 有任何想法吗?

try adding: 尝试添加:

WSGIPythonPath /home/vagrant/photoapp.com

at the top of your virtualhost config file. 在您的virtualhost配置文件的顶部。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM