2015-12-31 55 views
1

我有這樣的結構,我的包:無模塊名爲/父模塊3.5.0

/code_trou 
    __init__.py 
    Main.py 
    Menu.py 
    /postprocessing 
    /preprocessing 
    Mesh.py 
    Point.py 
    /processing 
     FDM.py 
    /tools 
     dllmrg.py 
     errormrg.py 
     /__pycache_ 
      errormrg.cpython-35.pyc 

當我執行我的Main.py有:

from tools.errormrg import * 

我有這樣的錯誤: "No module named 'tools'"

這是同樣的當我執行Point.py有:

from tools.dllmrg import * 

對於Point.py我試圖the Intra-package References described in the doc,它似乎並沒有工作:

from ..tools.dllmrg import * 
+2

你需要在'/ tools'一個'__init __。py',使一個模塊太(同爲其他子模塊)。 – jonrsharpe

回答

1

什麼使一個目錄Python包是__init__.py的存在:這個不是執行Point.py當我得到的錯誤"Parent module '' not loaded, cannot perform relative import"文件。您的toolsprocessing目錄中沒有這樣的文件,所以Python不會將它們識別爲包。

https://docs.python.org/3/tutorial/modules.html#packages