본문 바로가기
반응형

Python/오류 및 해결 방법3

Python pip install playsound error, playsound 설치 오류 Python에서 mp3파일 재생을 위해 playsound 라이브러리를 설치하려고 하는데 다음과 같이 오류가 발생하였다. pip install playsound pip 오류인가 했더니 그건 아니였다. 오류를 해결하기 위해 대충 구글링을 하였다... 결론은 playsound 라이브러리의 버전을 낮추는 것!! (괜찮겠지...?) pip install playsound==1.2.2 라이브러리를 설치하고 코드를 실행하니 문제없이 잘된다. 2023. 7. 23.
TypeError: 'str' object cannot be interpreted as an integer TypeError: 'str' object cannot be interpreted as an integer 에러가 발생했다면 `int` 자료형을 사용해야할 곳에 `str` 자료형을 사용해서 발생한 문제이다. 예를들면 다음과 같다. fruits 리스트에서 0번째 인덱스 `apple`을 삭제하려고 한다. fruits = ['apple', 'banana', 'orange'] fruits.pop('apple') # `apple`이 아닌 0을 넣어줘야한다... print(fruits) # TypeError: 'str' object cannot be interpreted as an integer index.pop() 함수의 인자값에는 int 자료형이 들어가야 한다. 위의 코드는 str 자료형을 넣었다. 그렇다면 올.. 2023. 7. 6.
TypeError: Can't instantiate abstract class with abstract method 추상 클래스를 상속받은 파생 클래스 내부에서 추상 클래스에서 선언한 추상 메소드를 구현하지 않았을 때 발생하는 오류이다. 파생 클래스 내부에 추상 메소드를 구현해주면 해결할 수 있다. 예시 오류 코드 from abc import ABC, abstractmethod class Animal(ABC): @abstractmethod def eat(self): pass class Dog(Animal): def __init__(self, name, age): self.name = name self.age = age doge = Dog("doge", 1) print(doge.name) print(doge.age) # 결과: TypeError: Can't instantiate abstract class Dog with.. 2023. 6. 25.
반응형