디버깅 ( 오류 해결 과정 )

labelme 설치 중 UnocodeDecodeError 해결법

왕현성 2023. 8. 25. 15:15
728x90
pip install labelme

아나콘다를 통해 위 명령어로 설치하는 도중에

 

(anomalib_env) C:\WINDOWS\system32>pip install labelme Looking in indexes: https://pypi.org/simple, https://pypi.ngc.nvidia.com Collecting labelme Downloading labelme-5.3.1.tar.gz (1.5 MB) ---------------------------------------- 1.5/1.5 MB 15.5 MB/s eta 0:00:00 Preparing metadata (setup.py) ... error error: subprocess-exited-with-error × python setup.py egg_info did not run successfully. │ exit code: 1 ╰─> [10 lines of output] Traceback (most recent call last): File "", line 2, in File "", line 34, in File "C:\Users\LEE CHANG YOUNG\AppData\Local\Temp\pip-install-y4b20jg0\labelme_111a18c52ad845bf9fca91aa6fd08208\setup.py", line 162, in main() File "C:\Users\LEE CHANG YOUNG\AppData\Local\Temp\pip-install-y4b20jg0\labelme_111a18c52ad845bf9fca91aa6fd08208\setup.py", line 125, in main long_description=get_long_description(), File "C:\Users\AppData\Local\Temp\pip-install-y4b20jg0\labelme_111a18c52ad845bf9fca91aa6fd08208\setup.py", line 75, in get_long_description long_description = f.read() UnicodeDecodeError: 'cp949' codec can't decode byte 0xf0 in position 3647: illegal multibyte sequence [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: metadata-generation-failed × Encountered error while generating package metadata. ╰─> See above for output. note: This is an issue with the package mentioned above, not pip. hint: See above for details.

 

이 에러가 발생했다.

 

해당 에러는 'labelme' 패키지를 설치하려 할 때 발생한 'UnicodeDecoderError'와 관련된 것이다.

 

에러 메시지를 자세히 살펴보면 'cp949'코덱이 특정 바이트를 디코딩할수 없다는 내용인 것을 확인할 수 있다.

 

'cp949'는 한글 윈도우에서 사용하는 문자 인코딩 방식이다.

 

이 문제는 'labelme'의 'setup.py'파일이 특정 인코딩으로 읽혀서 발생한 것으로 추측된다.

 

내가 해결한 방법은 다음과 같다.

 

우선 anaconda prompt에서 아래 명령어로 setup.py파일을 notepad에서 열어준다.

notepad setup.py
def get_long_description():
    with open("README.md") as f:
        long_description = f.read()
    try:
        # when this package is being released
        import github2pypi

        return github2pypi.replace_url(
            slug="wkentaro/labelme", content=long_description, branch="main"
        )
    except ImportError:
        # when this package is being installed
        return long_description

이 함수 부분에서 에러가 발생한 것인데, 위 코드를 아래와같이 수정해주면 된다.

 

def get_long_description():
    with open("README.md", 'r', encoding='utf-8') as f: # 수정된 부분
        long_description = f.read()
    try:
        # when this package is being released
        import github2pypi

        return github2pypi.replace_url(
            slug="wkentaro/labelme", content=long_description, branch="main"
        )
    except ImportError:
        # when this package is being installed
        return long_description