我想了解的問題是:導入錯誤和PYTHONPATH
我試圖導入一個模塊:
from main.models import Main
from django.contrib import admin
admin.site.register(Main)
然而,當我試圖打的管理網站,我得到一個Django的錯誤頁面:
ImportError at /admin/
cannot import name Main
I noticed that it provides a dump of the **Python Path:**
Python Path: ['/Users/brian/src/SampleApp/src/SampleApp', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload', '/Library/Python/2.6/site-packages', '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC', '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/wx-2.8-mac-unicode']
但是,我不明白的是這個Python路徑集在哪裏?
做一個export PYTHONPATH
沒有返回任何內容,因爲它沒有在環境變量中設置。
我需要導入它位於/Users/brian/src/SampleApp/src/SampleApp/main/models.py
感謝
是的,我有一個空的__init__.py那裏...愚蠢的我,主不在那裏。就是這樣。謝謝。 – 2010-11-07 00:10:50
任何想法設置PYTHONPATH? – 2010-11-07 00:11:21