麻烦为python安装selenium

Trouble installing selenium for python

我在Python中导入Selenium WebDriver时遇到一些问题。只是为了确保:这是我的小剧本:

1
2
3
import selenium
from selenium import webdriver
browser = webdriver.Firefox(executable_path='/Users/Sleeps/Webdrivers/Firefox/geckodriver')

当我奔跑

from selenium import webdriver

我犯了错误

No module named 'selenium.webdriver.firefox.webdriver'

我很好地遵循硒本身的建议步骤(你可以在这里找到它们)。不要紧,我得到了错误。我不知道为什么会这样。我尝试了以下方法:

pip install selenium

python -m pip install -U selenium

sudo pip3 install selenium

不管我用什么,pip证实

Requirement already satisfied: selenium in ./anaconda/lib/python3.5/site-packages

我进一步查了一下Python的目录。我确实在正确的地方有硒包装:/Users/Sleeps/anaconda/lib/python3.5/selenium/webdriver/__init__.py

编辑

我还为MacOS安装了最新的Gecko驱动程序(您可以在这里找到它)。我把它开箱给了Users/Sleeps/Webdrivers/Firefox/

我在命令行上运行了PATH=$PATH:/Users/Sleeps/Webdrivers/Firefox/geckodriver

运行from pprint import pprint; import os; import sys; pprint(sys.path); pprint(os.getenv("PATH")); pprint(os.getcwd())返回

1
2
3
4
5
6
7
8
9
10
11
12
13
14
['',
 '/Users/Sleeps/anaconda/lib/python3.5/site-packages/six-1.10.0-py3.5.egg',
 '/Users/Sleeps/anaconda/lib/python35.zip',
 '/Users/Sleeps/anaconda/lib/python3.5',
 '/Users/Sleeps/anaconda/lib/python3.5/plat-darwin',
 '/Users/Sleeps/anaconda/lib/python3.5/lib-dynload',
 '/Users/Sleeps/anaconda/lib/python3.5/site-packages',
 '/Users/Sleeps/anaconda/lib/python3.5/site-packages/Sphinx-1.4.1-py3.5.egg',
 '/Users/Sleeps/anaconda/lib/python3.5/site-packages/aeosa',
 '/Users/Sleeps/anaconda/lib/python3.5/site-packages/IPython/extensions',
 '/Users/Sleeps/.ipython']
'/Library/Frameworks/Python.framework/Versions/2.7/bin:/Users/Sleeps/anaconda/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin'
('/Users/Sleeps/Dropbox/01_Data '
 'Science/Kooperation/EX/Automobile‘)

ls -alh收益

1
2
3
4
total 24
drwxr-xr-x@  3 Sleeps  staff   102B  9 Aug 12:06 .
drwxr-xr-x@ 35 Sleeps  staff   1,2K  9 Aug 12:06 ..
-rwxr-xr-x@  1 Sleeps  staff   9,4K  9 Aug 11:59 Test.ipynb

当我运行from selenium import webdriver时,我仍然得到错误。我怎样才能摆脱它?


尝试如下:

在ubuntu/debian系统上,这将安装pip(和依赖项),然后从pypi安装Selenium-python绑定:

1
2
$ sudo apt-get install python-pip
$ sudo pip install selenium

安装后,以下代码应起作用:

1
2
3
4
5
6
#!/usr/bin/env python

from selenium import webdriver

browser = webdriver.Firefox()
browser.get('http://www.ubuntu.com/')