본문 바로가기

오늘의 오류들/Django

1. vscode에서 unable to import django.contrib.auth.models pylint(import-error)오류

[개발환경:ubuntu20.04 lts]


[오류 증상]

마이그레이션을 하려는데 import문제가 떠서 포스팅합니다.

 


[0.pylint란?]

 

오류 해결에 앞서 오류메시지에  pylint란 단어가 보여서 먼저 알아보았습니다.

 

pylint는 파이썬코드의 오류를 잡아내는 도구입니다. pep8이라는 파이썬 표준코드작성 방식과 비교하여

 

오류를 잡아냅니다.

 

(해당정보는 아래주소의 해당 블로그에서 알게되었습니다.)

https://exmemory.tistory.com/m/72

 

 


[1.문제 원인]

 

그래서 스택오버플로우 답변을 보면서 해결해보려 합니다.

https://stackoverflow.com/questions/48270385/vs-code-error-when-importing-django-moduleㅇㅇ

 

 

VS Code error when importing Django module

I'm working on a web app and I use Django as framework. I'm using VS Code on a macOS. I get an error when I try to import some Django module. This is a screenshot of my code in error. The error

stackoverflow.com

 

[본문내용]

I too was facing this error while working with Python virtual environments.
In my case, it was happening because I have installed Django on my virtual environment 
and my base environment didn't contain any module named Django.

So if VS code uses the Python interpreter from the base environment,
it will not recognize the Django module (import Error).
Therefore, you are required to change the Python interpreter to the one present 
in your virtual environment.

 

 

이 경우는 파이썬의 가상환경에서 작업할때 마주하는 문제입니다.

파이썬 인터프리터가 기본환경으로 한다면 장고 모듈을 인식 못하는 경우가 생깁니다.

그래서 파이썬 현재 가상환경에 맞게 인터프리터를 설정해줘야 합니다.


[2.인터프리터 선택]

 

 

 

 

여기에서 왼쪽 하단에 Python bit라는 부분을

클릭해줍니다.

 

 

 

 

 

 

그러면 사용할 수 있는 파이썬 인터프리터가 

뜹니다. 원하는 것을 선택해주시면 됩니다.

(저는 python 3.7.6 64bit를 선택했습니다.)

 

 

 

 


[3.결과]

해당 오류가 사라졌습니다.


[참고사이트]

https://exmemory.tistory.com/m/72

 

[Python] Pylint - 정의와 예제를 통해 Python 린트 툴 알아보기

Lint? 린트(lint) 또는 린터(linter)는 소스 코드를 분석하여 프로그램 오류, 버그, 스타일 오류, 의심스러운 구조체에 표시(flag)를 달아놓기 위한 도구들을 말합니다. 이 용어는 C 언어 소스 코드를

exmemory.tistory.com