2014-03-13 4 views
1

내 사이트 패키지 디렉토리에 패키지가 설치되어 있습니다. 나는 나와 MyPkg를 참조 help ('modules')을 수행 할 때 폴더 구조는 다음과__init__ 파일에서 가져올 때 파이썬 오류가 발생했습니다.

MyPkg\ 
    __init__.py 

    LogUtils\ 
    __init__.py 
    logwrapper.py 

    Shortcuts\ 
    __init__.py <-----this references LogUtils 
    somefile.py 

것 같습니다.

>>> import MyPkg 
>>> from MyPkg import LogUtils 
>>> from MyPkg import Shortcuts 

Traceback (most recent call last): 
    File "<pyshell#2>", line 1, in <module> 
    from MyPkg import Shortcuts 
    File "C:\Python27\lib\site-packages\MyPkg\Shortcuts\__init__.py", line 1, in <module> 
    from GoToUrl import go_to_url 
    File "C:\Python27\lib\site-packages\MyPkg\Shortcuts\GoToUrl.py", line 1, in <module> 
    from LogUtils import logger, log 
ImportError: No module named LogUtils 

왜 LogUtils 혼자 잘 서 가져올 것입니다하지만, 초기화 파일을 통해 가져올 때 오류가 발생 ?? :하지만 IDLE에서 다음과 같은 오류가

답변

0

당신이 자신을 볼 때, 당신은 동일한 모듈 수입되지 않은 부족한 나에게 보인다 :

>>> from MyPkg import LogUtils 

대를

from LogUtils import logger, log 

첫 번째에게 MyPkg.LogUtils 패키지를 가져오고 두 번째 패키지는 LogUtils 패키지를 가져옵니다. . 존재 여부는 파이썬 경로에 따라 다르지만 일반적으로 첫 번째 경로가 작동하는 경우 두 번째 경로를 변경하십시오.

from MyPkg.LogUtils import logger, log 
0

은 당신이 어떤 백 슬래시

MyPkg\ 
    __init__.py 

    LogUtils\ 
    __init__.py, \ 
    logwrapper.py 

    Shortcuts\ 
    __init__.py, \ 
    somefile.py 
관련 문제