본문 바로가기

웹 개발/Django

[Django] 장고 최신버전(3.0) ModuleNotFoundError: No module named 'django.utils.six' 오류 해결

본인이 사용하는 개발환경은 다음과 같다.

====================================

Windows 10 Home 64비트 운영 체제

Pycharm Professional 2019.2.4 (build 192.7142.42)

Python 3.8

Django 3.0.1

pip 19.3.1

====================================

 

Django 인스타그램 클론코딩 중 소셜로그인을 이용한 댓글 기능 구현 부분을 공부하던 중

 

https://www.youtube.com/watch?v=jN4z14mrEOk 해당 영상 4분 45초 부분의

disqus라는 사이트패키지를 사용한 후 적용시키기 위해 python manage.py migrate 명령어를 실행하자

다음과 같은 오류가 발생하였다.

구글링 해본 결과 

django가 3.x.x 버전으로 업데이트 하면서 django.utils.six라는 모듈이 삭제되었다.

해결 방법으로는 간단하게 그냥 django.utils.six 모듈 대신 six모듈을 사용하면 된다.

 

참고

https://stackoverflow.com/questions/59524941/modulenotfounderror-no-module-named-django-utils-six

 

ModuleNotFoundError: No module named 'django.utils.six'

HTTP GET /admin/ 500 [0.00, 127.0.0.1:51425] Traceback (most recent call last): File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\daphne\http_protocol.py",...

stackoverflow.com

 

django.utils.six 모듈을 six모듈로 변경하면 된다는 건데 문제는 어떻게 바꾸는 건지를 몰랐다.

 

그래서 다음의 six Docs문서를 읽어봤더니 생각보다 간단했다.

Docs문서 참고

https://six.readthedocs.io/

 

Six: Python 2 and 3 Compatibility Library — six 1.13.0 documentation

Binary and text data Python 3 enforces the distinction between byte strings and text strings far more rigorously than Python 2 does; binary data cannot be automatically coerced to or from text data. six provides several functions to assist in classifying s

six.readthedocs.io

 

오류가 뜬 disqus 디렉토리의 __init__.py 파일에서 다음과 같이 수정해주면 해결되었다.

(disqus 디렉토리의 경로를 모른다면 맨 위의 사진처럼 장고 자체에서 오류뜰때 알려주는 파란색 링크를 누르면 된다.)

# 으로 주석처리 된 부분의 구버전 코드이고 각 #아래가 수정한 코드이다.

간단하게 django.utils부분만 지워주고 문법을 살짝 수정하면 된다.

탭 자동완성 기능을 이용하자.

 

다시 python manage.py migrate를 시도하자 오류 없이 잘 실행되었다.

'웹 개발 > Django' 카테고리의 다른 글

[Django] Windows 개발환경에서 Pillow 설치 오류 해결  (0) 2019.12.25