簡體   English   中英

Django&WSGI-導入錯誤找不到模塊django

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

我正在為django項目配置的游民區中設置本地開發環境。 因此,virtualenv在這一點上實際上並沒有太多使用,所以我只是將所有模塊安裝在requirements.txt中

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

我的問題是,無論我嘗試了什么,我始終如一地

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'

應用程序文件夾結構為:

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

使用標准的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()

和一個虛擬主機文件:

<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>

但是每次我通過dev.photoapp.com訪問該站點(hosts文件已被修改)時,都會收到錯誤500和上面的回溯消息。

注意

  1. 從python shell內import django工程
  2. `python manage.py runserver可以使用URL 127.0.0.1:8000正常加載
  3. 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的/擴展]

因此,我可以看到django軟件包在路徑上是可訪問的。 但這不能解決Apache訪問問題。

有任何想法嗎?

嘗試添加:

WSGIPythonPath /home/vagrant/photoapp.com

在您的virtualhost配置文件的頂部。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM