에러해결/PYTHON

import win32com.client 에러 dll load failed

Zziii 2023. 8. 1. 14:41
728x90
반응형

 

win32com.client은 Windows 시스템에서 COM (Component Object Model) 객체와 상호 작용할 수 있는 Python 모듈이다.
COM은 소프트웨어 구성 요소를 만들고, 서로 통신하고, 상호 운용할 수 있게 하는 이진 표준이다.


Windows 환경에서 Microsoft Office 응용 프로그램을 자동화하고, Windows API에 접근하며, 기타 Windows 기반 소프트웨어와 상호 작용하는 데 널리 사용된다.

 

win32com.client 모듈은 Python에서 이러한 COM 객체를 편리하게 사용하고 접근할 수 있게 해준다.
이 모듈은 Python for Windows Extensions (PyWin32) 패키지의 일부로 제공되며, Python이 Windows 특정 서비스와 상호 작용할 수 있도록 다양한 모듈을 제공한다.

 

pip install pywin32

명령어를 입력하여 설치를 끝내고

 

import win32com.client

위 코드를 실행했을때

 

ImportError: DLL load failed 에러 발생

 

구글링을 해보니 여러가지 방법이 많았는데

 

첫번째 방법은 버전을 다운그레이드 해주는것

아나콘다 프롬프트 창이나 cmd 창에 아래와 같이 입력해준다.

pip install --upgrade pywin32==225

다음과 같이 입력하여 버전을 다운그레이드 해준다.

나같은 경우 다운그레이드를 해줘도 똑같은 에러가 발생했다.

 

 

그래서 두번째 방법으로 명령어를 다르게 입력해주었다.

conda install -c anaconda pywin32

이렇게 입력해서 설치를 재진행주니 잘 실행 되었다. 혹시 DLL load faied 에러는 해결되었는데

pywinerror가 발생한다면 에러해결>Python 글에 관련 에러글을 참고하여 32bit 가상환경을 생성하여 해결하면 된다.

 

 

win32coom.client 활용

엑셀다루기 예제

 import win32com.client

def excel_example():
    excel = win32com.client.Dispatch("Excel.Application")
    excel.Visible = True  # Excel 응용 프로그램 창을 보이도록 설정

    workbook = excel.Workbooks.Add()
    sheet = workbook.ActiveSheet

    sheet.Range("A1").Value = "안녕,"
    sheet.Range("B1").Value = "세상!"

    workbook.SaveAs("C:\\example.xlsx")
    workbook.Close()

    excel.Quit()

if __name__ == "__main__":
    excel_example()
728x90
반응형
let textNodes = document.querySelectorAll("div.tt_article_useless_p_margin.contents_style > *:not(figure):not(pre)"); textNodes.forEach(function(a) { a.innerHTML = a.innerHTML.replace(/`(.*?)`/g, '$1'); });