Python ModuleNotFoundError:没有名为“硒”的模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43797328/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ModuleNotFoundError: No module named 'selenium'
提问by Google User
I get an error while running this selenium script. Please suggest what can be done to fix this: Script:
运行此 selenium 脚本时出现错误。请建议可以做些什么来解决这个问题:脚本:
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'
回溯(最近一次调用):文件“C:/Users/admin/Desktop/test2.py”,第 2 行,在 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)
我已经在 win 7 Professional 32 位上安装了 Python 3.6。我有 Selenium 独立服务器版本 3.4.0(链接)
回答by shahin
Try installing selenium using pip. Use the following command.
尝试使用 pip 安装 selenium。使用以下命令。
python -m pip install -U selenium
回答by NAVNEET CHANDAN
Seems like you have not run the installation command for webdriver_manager.
好像你还没有运行 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:
但在此之前,请确保您也正确安装了 selenium。如果没有,请使用以下命令安装 selenium:
pip install selenium
回答by Dataku
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'
如果您使用的是像 virtualenv 这样的虚拟环境。
您必须确保模块 selenium 安装
1.) 在虚拟环境中和
2.) 在默认设置中(当虚拟环境停用时)。
否则,您将收到错误消息:
ModuleNotFoundError: No module named 'selenium'
Example
例子
Install selenium in the default settings: pip install selenium
在默认设置中安装 selenium: pip install selenium
Create virtual environment (on windows): py -m virtualenv folder_env
创建虚拟环境(在 Windows 上): py -m virtualenv folder_env
Activate virtual environment (on windows): source folder_env/Scripts/activate
激活虚拟环境(在 Windows 上): source folder_env/Scripts/activate
Check virtual environment settings: which python
and which pip
检查虚拟环境设置:which python
和which pip
Install selenium: pip install selenium
安装硒: pip install selenium
Check pip list for selenium: pip list
检查硒的 pip 列表: pip list
(Optional) Exit virtual environment: deactivate folder_env
(可选)退出虚拟环境: 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
Corey Schafer 的 Virtualenv:https: //www.youtube.com/watch?v=N5vscPTWKOk
virtualenv 不是本机模块,您必须安装它
pip install virtualenv
回答by Corey Goldberg
driver = webdriver.chrome("")
驱动程序 = webdriver.chrome("")
there is no such class ^^. It is named webdriver.Chrome()
没有这样的课程^^。它被命名为webdriver.Chrome()
回答by singopedia shaad
Okay, the Quick and Easy Solution is to Go to Your Python Version Location, Then Libs, and then Site-packages.
好的,快速简便的解决方案是转到您的 Python 版本位置,然后是 Libs,然后是 Site-packages。
ex -C:\Users\Admin\AppData\Local\Programs\Python\Python38\Lib\site-packages
例如 -C:\Users\Admin\AppData\Local\Programs\Python\Python38\Lib\site-packages
Try Deleting and Reinstalling Selenium, and Try Running the Code.