python无法安装selenium,无法为python安装Selenium

I have some trouble with importing selenium webdriver in python. Just to make sure: here is my little script:

import selenium

from selenium import webdriver

browser = webdriver.Firefox(executable_path='/Users/Sleeps/Webdrivers/Firefox/geckodriver')

When I run

from selenium import webdriver,

I am thrown the error

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

I neatly follow the steps suggested from Selenium themselves (you can find them here). Nonethelss, I get the error. I have no idea why that is the case. I tried the following:

pip install selenium

python -m pip install -U selenium

sudo pip3 install selenium

No matter what I use, pip confirms

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

I further cheked in the Anaconda directory. And I do seem to have the selenium package at the right place: /Users/Sleeps/anaconda/lib/python3.5/selenium/webdriver/__init__.py

EDIT

I further installed the latest gecko driver for MacOS (you can find it here). I unpacked it to Users/Sleeps/Webdrivers/Firefox/.

I ran PATH=$PATH:/Users/Sleeps/Webdrivers/Firefox/geckodriver in the comand line.

Running from pprint import pprint; import os; import sys; pprint(sys.path); pprint(os.getenv("PATH")); pprint(os.getcwd()) returns

['',

'/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 returns

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

When I run from selenium import webdriver, I still get the error.

How can I get rid of it?

解决方案

Try below :-

On Ubuntu/Debian systems, this will install pip (and dependencies) and then install the Selenium Python bindings from PyPI:

$ sudo apt-get install python-pip

$ sudo pip install selenium

After the installation, the following code should work:

#!/usr/bin/env python

from selenium import webdriver

browser = webdriver.Firefox()

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值