无法为python安装Selenium [英] Trouble installing selenium for python

查看:364
本文介绍了无法为python安装Selenium的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在python中导入Selenium Webdriver时遇到了一些麻烦.只是为了确保:这是我的小脚本:

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')

我跑步时

from selenium import webdriver

我被抛出错误

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

我完全按照Selenium本身的建议进行操作(您可以在此处找到它们) ).没关系,我得到了错误.我不知道为什么会这样.我尝试了以下方法:

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

无论我用什么,pip都会确认

No matter what I use, pip confirms

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

我进一步在Anaconda目录中che了一下.而且我似乎确实将硒包装放在正确的位置:/Users/Sleeps/anaconda/lib/python3.5/selenium/webdriver/__init__.py

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

编辑

我还为MacOS安装了最新的gecko驱动程序(您可以在此处找到它).我将其解压缩到Users/Sleeps/Webdrivers/Firefox/.

I further installed the latest gecko driver for MacOS (you can find it here). I unpacked it to 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())返回

['',
 '/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返回

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时,仍然出现错误. 我该如何摆脱呢?

When I run from selenium import webdriver, I still get the error. How can I get rid of it?

推荐答案

尝试以下方法:-

在Ubuntu/Debian系统上,这将安装pip(和依赖项),然后从 PyPI :

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

这篇关于无法为python安装Selenium的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆