기본 콘텐츠로 건너뛰기

6월, 2020의 게시물 표시

[pip install]distutils.errors.DistutilsPlatformError: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": https://visualstudio.microsoft.com/downloads/

안녕하세요 이번 포스팅은 pip를 설치하면서 발생하는 에러를 해결하는 방법에 대해서 알아보겠습니다. 개발 환경 OS: Windows 10 python: Python 3.8.0 pip: pip 19.3.1 저는 아래 두 개 라이브러리를 설치하면서 위와 같은 에러가 발생했습니다. pip install tensor2tensor  pip install konlpy 참고로 첫 번째 라이브러리는 transformer 모델을 설치하는 명령어이고 두 번째는 형태소 분석을 위한 라이브러 입니다. [Error Message] ERROR: Command errored out with exit status 1: command: 'c:\users\ynebu\appdata\local\programs\python\python38\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Public\\Documents\\ESTsoft\\CreatorTemp\\pip-install-b27rktjo\\gevent\\setup.py'"'"'; __file__='"'"'C:\\Users\\Public\\Documents\\ESTsoft\\CreatorTemp\\pip-install-b27rktjo\\gevent\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"&#

RuntimeError: Only Tensors of floating point dtype can require gradients

단위 테스트 중 에러가 발생하여 내용을 정리합니다. [Source] a = torch.tensor([1, 2], requires_grad=True) [Error Message] RuntimeError Traceback (most recent call last) in ----> 1 a = torch.tensor([1, 2], requires_grad=True) RuntimeError: Only Tensors of floating point dtype can require gradients 에러 문구를 한국말로 번역하면 다음과 같습니다. RuntimeError: Only Tensors of floating point dtype can require gradients floating point dtype 텐서만 gradients가 필요합니다. 문제점은 gradient를 지원하는 텐서의 타입은 floating인데, 텐서를 선언할 때 값을 torch.int32인 1, 2로 대입한게 문제였습니다. 미분한 결과는 소수점으로 나오니 어찌보면 당연한 내용입니다.  [Resolve] 다음은 해결 방법입니다. tensor를 선언할 때 floating 타입으로 선언하면 해결 됩니다. 참고로 둘 중 하나만 floating 타입으로 설정해도 tensor는 floating 타입으로 만들어 집니다. 또는 dtype=torch.float32을 별도로 선언해도 됩니다. a = torch.tensor([1., 2], requires_grad=True) # 하나만 torch.floating으로 선어 a = torch.tensor([1, 2.], requires_grad=True) # 하나만 torch.floating으로 선어 a = torch.tensor([1., 2.], requires_grad=True) a = torch.tensor([1, 2], dtype=torch.float32, requires_grad=True) #

TypeError: 'module' object is not callable

json파일을 읽어 데이터를 파싱하는 프로그램을 작성하는 중 다음과 같은 에러가 발생하면서  module object를 호출할 수 없습니다. import os import json import tqdm with open( os.path.join("/files/predictions_.json"), "r", encoding="utf-8" ) as reader: input_data = json.load(reader) for entry in tqdm(input_data): print(entry, input_data[entry]) [Error Message] TypeError: 'module' object is not callable [Resolve] tqdm import 하는 부분의 문제였습니다. tqdm 클래스의 파일명은 tqdm이므로 패키지 명을 from으로 선언해야 합니다. tqdm을 import 하기 위해서는 다음과 같이 선언해야 합니다. from tqdm import tqdm 감사합니다.