[파이썬 엑셀 파일 처리시 오류 해결하기] ImportError: Missing optional dependency ‘openpyxl’. Use pip or conda to install openpyxl.
openpyxl 관련 오류가 발생할때, 이미 설치한 경우라면 import문을 호출하지않아도 오류가 발생하지 않는다.
C:pythonProjectvenvScriptspython.exe C:/pythonProject/main.py Traceback (most recent call last): File “C:pythonProjectmain.py”, line 7, in <module> df = pandas.read_excel(“C:/Users/opening/Downloads/가맹점.xlsx”, engine=”openpyxl” File “C:pythonProjectvenvlibsite-packagespandasutil_decorators.py”, line 311, in wrapper return func(*args, **kwargs) File “C:pythonProjectvenvlibsite-packagespandasioexcel_base.py”, line 364, in read_excel io = ExcelFile(io, storage_options=storage_options, engine=engine) File “C:pythonProjectvenvlibsite-packagespandasioexcel_base.py”, line 1233, in __init__ self._reader = self._engines[engine](self._io, storage_options=storage_options) File “C:pythonProjectvenvlibsite-packagespandasioexcel_openpyxl.py”, line 521, in __init__ import_optional_dependency(“openpyxl”) File “C:pythonProjectvenvlibsite-packagespandascompat_optional.py”, line 118, in import_optional_dependency raise ImportError(msg) from None ImportError: Missing optional dependency ‘openpyxl’. Use pip or conda to install openpyxl. Process finished with exit code 1 |
openpyxl 해결방법
1. import openpyxl 모듈 관련 호출 구문 누락인지 먼저 체크한다.
import pandas
import os
import openpyxl
2. openpyxl 모듈이 설치되지 않았다면 설치 후 스크립트를 다시 Run한다.
– 설치 명령어 : pip install openpyxl
– 파이참을 이용중이라면 터미널창에서 명령어 실행하거나 import 선언 라인(빨간줄일테니)에서 마우스 올려서 설치 명령어를 클릭한다.
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
새로운 크로스 플랫폼 PowerShell 사용 https://aka.ms/pscore6
PS C:pythonProject> pip install openpyxl
Collecting openpyxl
Downloading openpyxl-3.0.9-py2.py3-none-any.whl (242 kB)
|████████████████████████████████| 242 kB ...
Collecting et-xmlfile
Downloading et_xmlfile-1.1.0-py3-none-any.whl (4.7 kB)
Installing collected packages: et-xmlfile, openpyxl
Successfully installed et-xmlfile-1.1.0 openpyxl-3.0.9
WARNING: You are using pip version 21.1.2; however, version 21.3 is available.
You should consider upgrading via the 'C:pythonProjectvenvScriptspython.exe -m pip install --upgrade pip' command.
PS C:pythonProject>
[참고]
https://playground.naragara.com/671