2

我收到以下错误:

ImportError at /
No module named midi_app
Request Method: GET
Request URL:    http://127.0.0.1:8000/
Django Version: 1.4.1
Exception Type: ImportError
Exception Value:    No module named midi_app
Exception Location: /Users/home/virtualenv/venv/lib/python2.7/site-packages/django/utils/importlib.py in import_module, line 35
Python Executable:  /Users/home/virtualenv/venv/bin/python

我已将我的应用程序“midi_app”添加到INSTALLED_APPSsettings.py 的部分。我不确定为什么会看到此错误。virtualenv 与它有什么关系吗?

谢谢。

更新:我已经添加了尽可能多的目录,但我仍然看到这个错误。请在下面查看我的路径。请帮忙,我真的很沮丧。

'/Users/home/virtualenv/venv/lib/python27.zip',

'/Users/home/virtualenv/venv/lib/python2.7',

'/Users/home/virtualenv/venv/lib/python2.7/plat-darwin',

'/Users/home/virtualenv/venv/lib/python2.7/plat-mac',

'/Users/home/virtualenv/venv/lib/python2.7/plat-mac/lib-scriptpackages',

'/Users/home/virtualenv/venv/lib/python2.7/lib-tk',

'/Users/home/virtualenv/venv/lib/python2.7/lib-old',

'/Users/home/virtualenv/venv/lib/python2.7/lib-dynload',

'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',

'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',

'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',

'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',

'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',

'/Users/home/virtualenv/venv/lib/python2.7/site-packages',

'/Users/home/Desktop/Web Development/Django-1.4',

'/Users/home/virtualenv/venv',

'/Users/home/Desktop/Web Development/Aptana Studio 3.0',

'/Users/home/virtualenv/venv/bin',

'/Users/home/桌面/Web 开发',

'/Users/home/virtualenv',

'/Users/home/virtualenv/venv/lib/python2.7/site-packages/PIL',

'/Users/home/virtualenv/venv/lib/python27.zip',

'/Users/home/virtualenv/venv/lib/python2.7/plat-darwin',

'/Users/home/virtualenv/venv/lib/python2.7/plat-mac',

'/Users/home/virtualenv/venv/lib/python2.7/plat-mac/lib-scriptpackages',

'/Users/home/virtualenv/venv/lib/python2.7/lib-tk',

'/Users/home/virtualenv/venv/lib/python2.7/lib-old'

4

3 回答 3

1

原来我的网址是错误的。

我将其指定为

url(r'^$', 'musicproject.midi_app.views.index'),

代替

 url(r'^$', 'midi_app.views.index'),

感谢你的帮助。

于 2012-11-06T08:06:24.860 回答
0

另一件需要注意的事情,你必须有一个:

__init__.py 

文件(空的很好,只需使用“touch init .py”)在通向您的应用程序的每个目录中位于 python 路径中。

因此,如果您有这样的结构:

my_project/
    manage.py
    __init__.py
    urls.py
    settings.py
    apps/
        __init__.py <---- this has to be here
        midi_app/
            __init__.py <--- this also has to be here
            models.py
            admin.py
            views.py
            urls.py

这很容易被忽视。

于 2012-11-04T02:11:55.980 回答
0

不,virtualenv 与此错误无关。ImportError这意味着它无法在您指定的位置找到您的应用程序,请重新检查应用程序的路径和您提供的路径以及名称。

于 2012-11-03T09:32:35.033 回答