[Python] AttributeError: partially initialized module "package_name" has no attribute "[package_name].attribute" (most likely due to a circular import)

 "AttributeError: partially initialized module "package_name" has no attribute "[package_name].attribute" (most likely due to a circular import)"

오류: "이 package는 요청하는 요소|선언 (attibute)이 없다."

이유: package 이름과 개발자가 작성 중이 파일명이 동일한 경우 발생한다.

예시:

mypkg.py

//

import mypkg as mp


mp.test()

//

python mypkg.py

...

AttributeError: partially initialized module "mypkg" has no attribute "test" (most likely due to a circular import)

해결방법: mypkg를 mypkg_test.py와 같이 변경하자.


mypkg_test.py

//

import mypkg as mp


mp.test()

//

python mypkg.py

...

This is my python test!


댓글

이 블로그의 인기 게시물

Next.js에서 자연스러운 Page Transition 방법

[flutter] Android - Package간 sdk version 등이 맞지 않아 오류가 발생하는 경우

[Windows] Chocolatey upgrade