2010-01-27 34 views
1
import sys 
print sys.path 

['D:\\zjm_code\\register2', 'C:\\WINDOWS\\system32\\python25.zip', 'D:\\Python25\\DLLs', 'D:\\Python25\\lib', 'D:\\Python25\\lib\\plat-win', 'D:\\Python25\\lib\\lib-tk', 'D:\\Python25', 'D:\\Python25\\lib\\site-packages'] 

我PYTHONPATH具有 '寄存器2',爲什麼我不能導入它

#from django.core.management import setup_environ 
from register2 import settings 
#setup_environ(settings) 

Traceback (most recent call last): 
    File "D:\zjm_code\register2\b.py", line 4, in <module> 
    from register2 import settings 
ImportError: No module named register2 

爲什麼,

感謝

回答

5

當目錄'D:\\zjm_code\\register2'sys.path,這意味着你可以導入模塊和包是INSIDE那個目錄。

要導入目錄register2本身,兩個條件:

  1. 'D:\\zjm_code',必須在sys.path;
  2. 文件'D:\\zjm_code\\register2\\__init__.py'必須存在

__init__.py是當你「導入目錄」實際執行的代碼。

0

哈哈,因爲它試圖從寄存器2中導入某些東西,但它不能在路徑上存在D:\ zjm_code ..