ModuleNotFoundError: No module named 'selenium'

女生的网名这么多〃 提交于 2020-04-14 06:26:51

问题


I get an error while running this selenium script. Please suggest what can be done to fix this: Script:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import re
import csv
import time
driver = webdriver.chrome("<webdriver path>")

driver.get("https://www.google.com/")
driver.find_element_by_xpath('//*[@title="Search"]')
send_keys('abc')
driver.find_element_by_xpath('//*[@class="sbico _wtf _Qtf"]').click()
time.sleep(5)
driver.find_element_by_xpath('//[@id="rso"]/div[1]/div/div[1]/div/div/h3/a')
print(var)

Error:

Traceback (most recent call last): File "C:/Users/admin/Desktop/test2.py", line 2, in from selenium import webdriver ModuleNotFoundError: No module named 'selenium'

I have installed Python 3.6 on win 7 Professional 32 bit. I have Selenium Standalone Server version 3.4.0(link)


回答1:


Try installing selenium using pip. Use the following command.

python -m pip install -U selenium



回答2:


Seems like you have not run the installation command for webdriver_manager.

Use the following command:

pip install webdriver_manager

But before this, make sure you have properly installed selenium as well. If not, use the following command to install selenium:

pip install selenium



回答3:


driver = webdriver.chrome("")

there is no such class ^^. It is named webdriver.Chrome()




回答4:


Remarks to virtual environments

virtualenv

If you are using a virtual environment like virtualenv.
You have to make sure that the module selenium is installed
1.) in the virtual environment and
2.) in the default settings (when the virtual environment is deactivated).

Otherwise you will get the error message:
ModuleNotFoundError: No module named 'selenium'

Example

Install selenium in the default settings: pip install selenium

Create virtual environment (on windows): py -m virtualenv folder_env

Activate virtual environment (on windows): source folder_env/Scripts/activate

Check virtual environment settings: which python and which pip

Install selenium: pip install selenium

Check pip list for selenium: pip list

(Optional) Exit virtual environment: deactivate folder_env

Miscellaneous

Virtualenv by Corey Schafer: https://www.youtube.com/watch?v=N5vscPTWKOk
virtualenv is not a native module, you have to install it with pip install virtualenv



来源:https://stackoverflow.com/questions/43797328/modulenotfounderror-no-module-named-selenium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!