python 실행 오류 ModuleNotFoundError: No module named ‘selenium’

python post logo 파이썬

다음과 같은 에러 메시지가 표시 되었다면 Python 추가 패키지 ‘selenium‘가 설치되어있지 않다는 것을 의미합니다. 추가 패키지 ‘selenium‘은 브라우저를 자동으로 조작하는 라이브러리입니다. 주로 웹 어플리케이션의 테스트 및 Web scraping에 이용됩니다.

오류 예

D:\>python test.py
Traceback (most recent call last):
  File "D:\test.py", line 1, in <module>
    from selenium import webdriver
ModuleNotFoundError: No module named 'selenium'

확인 소스

위의 오류 내용은 다음 소스를 test.py 파일 명으로 저장해서 실행 확인했습니다.

from selenium import webdriver

driver = webdriver.Chrome('chromedriver.exe')
driver.get("https://tech.zinnunkebi.com")
driver.close()
driver.quit()

selenium 패키지 설치 하기

Python 추가 패키지 ‘selenium‘의 설치 결과는 다음과 같습니다.

C:\>pip install selenium
Collecting selenium
  Downloading selenium-4.1.0-py3-none-any.whl (958 kB)
     |████████████████████████████████| 958 kB 233 kB/s
Collecting trio~=0.17
  Downloading trio-0.19.0-py3-none-any.whl (356 kB)
     |████████████████████████████████| 356 kB 3.3 MB/s
Requirement already satisfied: urllib3[secure]~=1.26 in c:\users\administrator\appdata\local\programs\python\python39\lib\site-packages (from selenium) (1.26.7)
Collecting trio-websocket~=0.9
  Downloading trio_websocket-0.9.2-py3-none-any.whl (16 kB)
Collecting async-generator>=1.9
  Downloading async_generator-1.10-py3-none-any.whl (18 kB)
Collecting sniffio
  Downloading sniffio-1.2.0-py3-none-any.whl (10 kB)
Collecting outcome
  Downloading outcome-1.1.0-py2.py3-none-any.whl (9.7 kB)
Requirement already satisfied: idna in c:\users\administrator\appdata\local\programs\python\python39\lib\site-packages (from trio~=0.17->selenium) (3.3)
Collecting attrs>=19.2.0
  Downloading attrs-21.2.0-py2.py3-none-any.whl (53 kB)
     |████████████████████████████████| 53 kB 766 kB/s
Collecting sortedcontainers
  Downloading sortedcontainers-2.4.0-py2.py3-none-any.whl (29 kB)
Collecting cffi>=1.14
  Downloading cffi-1.15.0-cp39-cp39-win_amd64.whl (180 kB)
     |████████████████████████████████| 180 kB 2.2 MB/s
Collecting wsproto>=0.14
  Downloading wsproto-1.0.0-py3-none-any.whl (24 kB)
Requirement already satisfied: certifi in c:\users\administrator\appdata\local\programs\python\python39\lib\site-packages (from urllib3[secure]~=1.26->selenium) (2021.10.8)
Collecting pyOpenSSL>=0.14
  Downloading pyOpenSSL-21.0.0-py2.py3-none-any.whl (55 kB)
     |████████████████████████████████| 55 kB 1.1 MB/s
Collecting cryptography>=1.3.4
  Downloading cryptography-36.0.0-cp36-abi3-win_amd64.whl (2.2 MB)
     |████████████████████████████████| 2.2 MB 128 kB/s
Collecting pycparser
  Downloading pycparser-2.21-py2.py3-none-any.whl (118 kB)
     |████████████████████████████████| 118 kB 273 kB/s
Requirement already satisfied: six>=1.5.2 in c:\users\administrator\appdata\local\programs\python\python39\lib\site-packages (from pyOpenSSL>=0.14->urllib3[secure]~=1.26->selenium) (1.16.0)
Collecting h11<1,>=0.9.0
  Downloading h11-0.12.0-py3-none-any.whl (54 kB)
     |████████████████████████████████| 54 kB 4.1 MB/s
Installing collected packages: pycparser, cffi, attrs, sortedcontainers, sniffio, outcome, h11, cryptography, async-generator, wsproto, trio, pyOpenSSL, trio-websocket, selenium
Successfully installed async-generator-1.10 attrs-21.2.0 cffi-1.15.0 cryptography-36.0.0 h11-0.12.0 outcome-1.1.0 pyOpenSSL-21.0.0 pycparser-2.21 selenium-4.1.0 sniffio-1.2.0 sortedcontainers-2.4.0 trio-0.19.0 trio-websocket-0.9.2 wsproto-1.0.0

참고로 pip명령은 Python 추가 패키지의 설치 등을 실시하는 python 유틸리티입니다. 명령 사용에 대한 자세한 내용은 “Python 유틸리티 pip” 글을 참조하십시오

추가 설치된 패키지를 확인하려면 다음 명령을 실행합니다.

D:\>pip freeze
altgraph==0.17.2
async-generator==1.10
attrs==21.2.0
beautifulsoup4==4.10.0
bs4==0.0.1
certifi==2021.10.8
cffi==1.15.0
charset-normalizer==2.0.7
cryptography==36.0.0
cx-Oracle==8.2.1
cycler==0.11.0
fonttools==4.28.2
future==0.18.2
h11==0.12.0
idna==3.3
kiwisolver==1.3.2
matplotlib==3.5.0
MouseInfo==0.1.3
numpy==1.21.4
opencv-python==4.5.4.60
outcome==1.1.0
packaging==21.3
pefile==2021.9.3
Pillow==8.4.0
PyAutoGUI==0.9.53
pycparser==2.21
PyGetWindow==0.0.9
pyinstall==0.1.4
pyinstaller==4.5.1
pyinstaller-hooks-contrib==2021.3
PyMsgBox==1.0.9
pyocr==0.8.1
pyOpenSSL==21.0.0
pyparsing==3.0.6
pyperclip==1.8.2
PyRect==0.1.4
PyScreeze==0.1.28
python-dateutil==2.8.2
pytweening==1.0.4
pywin32-ctypes==0.2.0
requests==2.26.0
selenium==4.1.0
setuptools-scm==6.3.2
six==1.16.0
sniffio==1.2.0
sortedcontainers==2.4.0
soupsieve==2.3.1
tomli==1.2.2
trio==0.19.0
trio-websocket==0.9.2
urllib3==1.26.7
wsproto==1.0.0

webdriver.Chrome(‘chromedriver.exe’) 에서 지정한 드라이버의 버전과 Browser의 버전이 일치하지 않아서 발생하는 오류에 대해서는 “Python Selenium “This version of ChromeDriver only supports Chrome version 89” 버전 오류” 글을 참조하십시오.

제목과 URL을 복사했습니다