import - Importing Python module from another module in the same level -


i working on python package basic structure listed below, , examples of each python file contains in curly brackets.

main_package/     setup.py     main_package/         __init__.py          {          import package1         import package2         __all__=['main_package']         }         package1/             __init__.py             {             import module1             import module2             __all__=['package1']             }             module1/                 __init__.py                 {                 script1 import class1a, class1b                 __all__ = ['script1']                 }                 script1.py                 {contains 2 classes: class1a , class1b}              module2/                 __init__.py                 {                 script2 import class2a, class2b                 __all__ = ['script2']                 }                 script2.py                 {contains 2 classes: class2a, class2b}              module3/                 __init__.py                 {                 script3 import class3a, class3b                 __all__ = ['script3']                  }                 script3.py                 {contains 2 classes: class3a, class3b}          package2/                 executable_script.py 

it has not given me trouble date. however, have added new module not import correctly (module3). have found few related threads, none of particular flavor.

i can install setup.py, , command line (any directory), following imports correctly:

python >>> main_package.package1.module3.script3 import class3a, class3b 

but, when copy same line script2 , rerun setup.py file (without error), following error when run executable_script:

importerror: cannot import name class3a 

and same error when try import python via command line. but, have problem when try import class3a script3 script2, not importing analogous classes script1 script2. difference can see script3 newer module script1. there may not updated in order me import new module/class older script? or there wrong structure bound catch me?

another detail error occurs when line added module @ same level, error originates in executable_script.py in package2. e.g. first line of error message

/usr/bin/executable_script, line 9, in <module>load_entry_point('main_package==0.1.0','console_scripts','executable_script')().

line 9 of executable script part of doc string. using python 2.7.

probably in circular import. in classa import classb , in somewhere in classb import classa or more files, in classa import class b, in classc import classb , classa.

try using absolute import:

from .script3 import class3a 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -