Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 没有名为webdriver的模块_Python 2.7_Selenium_Selenium Webdriver - Fatal编程技术网

Python 2.7 没有名为webdriver的模块

Python 2.7 没有名为webdriver的模块,python-2.7,selenium,selenium-webdriver,Python 2.7,Selenium,Selenium Webdriver,我刚刚为Python安装了Selenium(我是新来的) sudo -H pip install selenium 按以下命令 from selenium.webdriver import Firefox 我明白了 没有名为webdriver的模块 有什么想法吗?首先需要导入 from selenium import webdriver 然后,您可以使用其他导入检查是否在系统环境变量中添加了站点包链接 C:\Python27\Lib\site包 在windows开始时,键入环境变量。单击

我刚刚为
Python
安装了
Selenium
(我是新来的)

sudo -H pip install selenium
按以下命令

from selenium.webdriver import Firefox 
我明白了

没有名为webdriver的模块


有什么想法吗?

首先需要导入

from selenium import webdriver

然后,您可以使用其他导入检查是否在系统环境变量中添加了站点包链接

C:\Python27\Lib\site包


在windows开始时,键入环境变量。单击“编辑系统环境变量”。单击系统变量下的->环境变量->向下滚动找到“路径”->编辑并添加上面的路径。

最有可能的是调用了Python文件


Python解释器首先尝试从您所在的目录导入文件,因此,解决方案是重命名已执行的文件,问题将消失。

您能否
导入selenium
并检查
selenium.\uuuu文件\uuuuuuuuu
是否指向实际包含
webdriver
的正确文件夹?在此处尝试了相同的导入,但似乎没有任何错误。只是
import selenium
是否也会导致错误?为什么在sudo上使用H标志?我们还想知道
sudo-H
标志。我从不需要使用它。我使用H标志是因为我的Ubuntu系统在我最初安装时建议使用它。这不是必需的。为什么你这么认为?如果我不导入上面的内容,那么我的脚本将不知道什么是webdriver…这就是为什么我的代码在不单独导入webdriver的情况下工作的原因,这对我来说很有意义。如果你是对的,这就意味着你总是需要导入包层次结构的每一层。如果你根本不导入脚本,你是如何理解你在说什么的,对于selenium…我在说python@thebadguy,如果您从selenium.webdriver导入Firefox
,则应将其用作
driver=Firefox()
!当你从
webdriver
模块中分别导入
Firefox
类时,不能将其称为
webdriver.Firefox()